Moving Ball Using Applet and Timer Class
This is a simple program using applet and Timer class in java which shows the simulation of a moving ball.
Screenshot:
Screenshot:
The Code:
import java.applet.Applet; import java.awt.*; import java.util.TimerTask; import java.util.Timer; // @author Ankur Raj public class Timer_1 extends Applet { Timer timer; int bx=100; int by=100; int bxv=2; int byv=2; int refresh=5; public void init() { timer =new Timer(); timer.schedule(new TimerTask() { public void run() { bx=bx+bxv; by=by+byv; repaint(); } },0,refresh); } public void paint(Graphics g) { g.fillOval(bx, by, 50, 50); } }
Found bugs?
Report us, we will happy to fix'em !
Comments
Post a Comment