FileDocCategorySizeDatePackage
BouncingCircle.javaAPI DocExample2512Mon Sep 22 13:30:30 BST 1997None

BouncingCircle

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 voidanimate()
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();
  
public voidpaint(java.awt.Graphics g)
Draw the circle at its current position


          
      
    g.setColor(Color.red);
    g.fillOval(x-r, y-r, r*2, r*2);
  
public voidstart()
Start the timer when the browser starts the applet

 timer.start_animation(); 
public voidstop()
Pause the timer when browser pauses the applet

 timer.pause_animation();