/***************************************** * An abstract class that handles the specifics * of animation. All the user has to do is * implement subclass specific behavior. *****************************************/ public abstract class AnimationApplet extends java.applet.Applet implements Runnable{ // the thread that does the redrawing private Thread animationThread = null; // how often the thread redraws itself private int delay; public void start(){ if (animationThread == null){ animationThread = new Thread(this); animationThread.start(); } } public void stop(){ animationThread = null; } public void run(){ while (Thread.currentThread() == animationThread){ repaint(); try{ Thread.currentThread().sleep(delay); } catch(InterruptedException e){/* don't do anything*/} } } // Java bean pattern to enforce encapsulation public void setDelay(int delay){ this.delay = delay; } // Java bean pattern to enforce encapsulation public int getDelay(){ return delay; } }