// GenericAnimation.java import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GenericAnimation extends JApplet implements ActionListener { private int animationDelay = 50; // millisecond delay private Timer animationTimer; // Timer drives animation private int x, y; // respond to Timer's event public void actionPerformed( ActionEvent actionEvent ) { repaint(); // repaint animator } // start or restart animation public void startAnimation() { if ( animationTimer == null ) { animationTimer = new Timer( animationDelay, this ); animationTimer.start(); } else // continue from last image displayed if ( ! animationTimer.isRunning() ) animationTimer.restart(); } // stop animation timer public void stopAnimation() { animationTimer.stop(); } public void init() { startAnimation(); // begin animation } public void paint (Graphics g) { super.paint(g); g.fillOval(x++,y++,10,10); } }