import java.applet.*;
import java.awt.event.*;
import java.awt.*;
/*
<applet code=prg2
height=500 width=500>
</applet>
*/
public class prg2 extends Applet implements Runnable
{
int x1,y1,x2,y2,x3,y3,x4,y4,r=70;
int w,h;
Thread t;
int i=1;
public void init()
{
x1=0;x3=0;y1=0;y2=0;
x4=getWidth()-r;
x2=x4;
y4=getHeight()-r;
y3=y4;
w=getWidth()/2;
h=getHeight()/2;
}
public void start()
{
t=new Thread(this);
t.start();
}
public void run()
{
try
{
while(i<=(w/2)+2)
{
x1+=2;
x2-=2;
x3+=2;
x4-=2;
y1+=2;
y2+=2;
y3-=2;
y4-=2;
repaint();
Thread.sleep(100);
i++;
}
repaint();
}
catch(Exception e)
{}
}
public void paint(Graphics g)
{
if(i>=(w/2)-17)
{
g.setColor(Color.green);
g.fillOval(x1,y1,r,r);
g.setColor(Color.yellow);
g.fillOval(x2,y2,r,r);
g.setColor(Color.blue);
g.fillOval(x3,y3,r,r);
g.setColor(Color.red);
g.fillOval(x4,y4,r,r);
}
else
{
g.setColor(Color.green);
g.fillOval(x1,y1,r,r);
g.fillOval(x2,y2,r,r);
g.fillOval(x3,y3,r,r);
g.fillOval(x4,y4,r,r);
}
}
}
4 Corner Circle Move Java Applet
Reviewed by Unknown
on
8:56 pm
Rating:
No comments: