Simple animation applet
Our simple applet follows this logic:
At each call of the paint method, erase the entire canvas area, then draw the ball in it’s new location, and add some values to the x, y position of the ball.
Some simple bounds checking is provided, and the “repaint()” call from within paint create an animation loop for us.
The “repaint()” within paint eliminates the need for threading (not yet covered), but may cause problems for some browsers (e.g., Netscape). An appropriate sleep call can help:
try{
Thread.sleep (10); // lets gc occur in Netscape
} catch (InterruptedException e) { … }