public class BouncingCircle extends Applet implements Animation
An applet that displays a simple animation
Fields Summary
int
x
int
y
int
r
int
dx
int
dy
AnimationTimer
timer
A timer for animation: call our animate() method ever 100
milliseconds. Creates a new thread.
Constructors Summary
Methods Summary
public void
animate()
Move and bounce the circle and request a redraw.
The timer calls this method periodically.
// Bounce if we've hit an edge.
if ((x - r + dx < 0) || (x + r + dx > bounds().width)) dx = -dx;
if ((y - r + dy < 0) || (y + r + dy > bounds().height)) dy = -dy;
// Move the circle.
x += dx; y += dy;
// Ask the browser to call our paint() method to draw the circle
// at its new position.
repaint();