/*
CG
TOPIC: TO DISPLAY BOUNCING OF A BALL IN JAVA
*/
import java.applet.*;
import java.awt.*;
public class ball extends Applet implements Runnable
{
Thread t;
int x = 0;
int y = 0;
public void start()
{
t = new Thread(this);
t.start();
}
public void paint(Graphics g)
{
System.out.println("CODED BY TG ");
g.fillOval(x,y,100,100);
}
public void run()
{
try
{
for(;;)
{
for(;;)
{
if(y == 300)
{
System.out.print("\007");
break;
}
else
{
y = y +3;
x = x;
Thread.sleep(100);
repaint();
}
}
for(;;)
{
if(y==0)
{
System.out.print("\007");
break;
}
else
{
y = y-3;
x = x+3;
Thread.sleep(100);
repaint();
}
}
run();
}
}
catch(InterruptedException e)
{
}
}
}
/* CODED BY TG
<applet code = "ball" width = 1000 height = 1000> </applet> */
No comments:
Post a Comment