We have come up with few more core java projects.This time we decided to create some thing graphically beautiful.So we came up  with java animation.

In this blog post few animation programs are given.All they are using core java only.Along with output,Source code also given:

 

Java Animation Example : 1

Simple Animation in Java

Here is output:

Here is source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package puretechy.javaprojects;
 
import java.awt.*;
import java.applet.*;
 
public class Simple_Animation extends Applet
{
	 Color c1,c2,c3,c4,c5;
	 int temp;
	 public void init()
	 {
		 c1 = new Color(255, 128, 128);
		 c2 = new Color(255, 128,255);
		 c3 = new Color(255, 00,128);
		 c4 = new Color(255, 179,217);
		 c5 = new Color(128, 0,64);
		 newthread s=new newthread(this);
		 temp=0;	 
	 }
 
	 public void paint(Graphics g)
	 {
		 if(temp==0)
		 {
			 c1 = new Color(255, 128, 128);
			 c2 = new Color(255, 128,255);
			 c3 = new Color(255, 00,128);
			 c4 = new Color(255, 179,217);
			 c5 = new Color(128, 0,64);
		 }
 
		 if(temp==1)
		 {
			 c1 = new Color(255,255,128);
			 c2 = new Color(226, 193,3);
			 c3 = new Color(211, 100,18);
			 c4 = new Color(170, 162,0);
			 c5 = new Color(199, 148,80);
		 }
 
		 if(temp==2)	
		 {
			 c1 = new Color(128, 128, 255);
			 c2 = new Color(0, 128,192);
			 c3 = new Color(64,128,128);
			 c4 = new Color(0, 0,160);
			 c5 = new Color(64, 0,64);
		 }
		 g.setColor(c1); 
		 g.fillRect(0, 0, 200, 200);
		 g.setColor(c2); 
		 g.fillRect(20, 20, 160, 160);
		 g.setColor(c3); 
		 g.fillRect(40, 40, 120, 120);
		 g.setColor(c4); 
		 g.fillRect(60, 60, 80, 80);
		 g.setColor(c5); 
		 g.fillRect(80, 80, 40, 40);
	 }
}
class newthread implements Runnable
{
 Thread t;
 Simple_Animation obj;
 newthread(Simple_Animation obj)
 {
	 this.obj=obj;
	 t=new Thread(this ,"animate");
	 t.start();
 }
 public void run()
 {
	 try
	 {
		 for(;;)	
		 {
			 Thread.sleep(300);
			 if(obj.temp==0)
			 {
				 obj.temp=1;
			 }
			 else if(obj.temp==1)
			 {
				 obj.temp=2;
			 }
			 else
			 {
				 obj.temp=0;
			 }
			 obj.repaint();	
		 }
	 }
	 catch(Exception e)
 
	 {
		 System.out.println(e);
	 }
	 } 
}
}

Java Animation Example : 2

Animation effect Like Running Cycle

Here is output:

Here is source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package puretechy.javaprojects;
 
import java.awt.*;
import java.applet.*;
public class Simple_Animation_cycle extends Applet
{
	//XlineStart,YlineStart,XlineEnd,YlineEnd
	 int xls=15,yls=20,xle=50,yle=20;
	//XCircle1,YCircle1
	 int xc1=10,yc1=10;
	//XCircle2,YCircle2
	 int xc2=40,yc2=10;
	 public void init()
	 {
		 newthread s=new newthread(this);
	 }
 
	 public void paint(Graphics g)
	 {
 
		 g.drawLine(xls, yls, xle, yle);
		 g.drawOval(xc1, yc1, 20, 20);
		 g.drawOval(xc2, yc2, 20, 20);
	 }
 
}
class newthread implements Runnable
{
	 Thread t;
	 Simple_Animation_cycle obj;
	 newthread(Simple_Animation_cycle obj)
	 {
		 this.obj=obj;
		 t=new Thread(this ,"animate");
		 t.start();
	 }
 
	 public void run()
	 {
		 try
		 {
			 for(;;)
			 {
			 Thread.sleep(300);
			 obj.xls=obj.xls+5;
			 obj.xle=obj.xle+5;
			 obj.xc1=obj.xc1+5;
			 obj.xc2=obj.xc2+5;
			 if(obj.xle==400)
			 {
				 obj.xls=15;
				 obj.xle=50;
				 obj.xc1=10;
				 obj.xc2=40;
			 }
			 obj.repaint(); 
			}
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
 
	} 
 
}

Java Animation Example : 3

Animation effect Like Burning Crackers

Here is output:

Here is source code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package puretechy.javaprojects;
 
import java.awt.*;
import java.applet.*;
 
public class Simple_Animation_Crackers extends Applet
{
 Color c1,c2,c3,c4;
 int temp;
 public void init()
 {
	 c1 = new Color(255, 00, 00);
	 c2 = new Color(0, 150,0 );
	 c3 = new Color(0, 00,100);
	 c4 = new Color(0, 20,30);
	 newthread s=new newthread(this);	
	 temp=0;
 }
 public void paint(Graphics g)
 {
	 if(temp==0)
	 {
	 c1 = new Color(255, 00, 00);
	 c3 = new Color(0, 00,150);
	 }
	 if(temp==1)
	 {
	 c1 = new Color(10, 00,150);
	 c3 = new Color(255, 00, 00);
	 } 
 
	 //void drawLine(int startX, int startY, int endX, int   endY)
	 //void fillRect(int top, int left, int width, int height)
	 //g.drawOval(10, 10, 50, 50);
	 //void drawArc(int top, int left, int width, int height,int startAngle,int sweepAngle)
 
	 g.setColor(c4);
	 g.fillRect(0, 0, 400, 400);
	 g.setColor(c1);
	 g.drawArc(150, 150, 70, 70, 0, 80);
	 g.drawArc(225, 150, 70, 70, 110,78);
	 g.drawLine(223, 190,223 ,140);
	 g.setColor(c2);
	 g.drawLine(225, 190,220 ,190);
	 g.drawLine(205, 220,220 ,190);
	 g.drawLine(205, 220,240 ,220);
	 g.drawLine(225, 190,240 ,220);
	 g.setColor(c3);
	 g.drawOval(182, 150, 7, 7);
	 g.drawOval(250, 150, 7, 7);
	 g.drawOval(222, 130, 7, 7);
 }
}
class newthread implements Runnable
{
	 Thread t;
	 Simple_Animation_Crackers obj;
	 newthread(Simple_Animation_Crackers obj)
 
	 {
 
	 this.obj=obj;
 
	 t=new Thread(this ,"animate");
 
	 t.start();
 
	 }
 
	 public void run()
	 {
		 try
		 {
			 for(;;)
			 {
				 Thread.sleep(300);
				 if(obj.temp==0)
				 {
					 obj.temp=1;
				 }
				 else
				 {
					 obj.temp=0;
				 }
				 obj.repaint();
			 }
		 }
		 catch(Exception e)
		 {
			 System.out.println(e);
		 }
	 } 
}

Hope these programs help you.!

Please Let us know your views about the Java animation programs in comment section.and also let us know if any queries.Will try to resolve as soon as possible.:)

You know what creating mini paint project in java is also damn easy.See source code here.

Hey wait,You might be interested in some more free learning.We promise completely free.We have listed so many free coupons for best Udemy courses.

Check out here.It may change your learning experience!

Keep Learning !

About

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website

%d bloggers like this: