import java.awt.*; import java.applet.Applet; public class AppletAnimatorSimple extends java.applet.Applet implements Runnable { int frame; int delay; Thread animator; // Initialize the applet and compute the delay between frames. public void init() { animator = new Thread(this); animator.start(); } // This method is called when the applet is no longer // visible. Set the animator variable to null so that the // thread will exit before displaying the next frame. public void stop() { animator = null; } // This method is called by the thread that was created in // the start method. It does the main animation. public void run() { //This is the animation loop. while (true) { //Advance the animation frame. frame++; //Display it. repaint(); //Delay depending on how far we are behind. try { Thread.sleep(100); } catch (Exception e) { break; } } } //Draw the current frame of animation. public void paint(Graphics g) { g.drawString("Frame: " + frame, 30, 30); } }