FileDocCategorySizeDatePackage
UpdateApplet.javaAPI DocExample840Mon May 01 14:41:42 BST 2000None

UpdateApplet.java

//file: UpdateApplet.java
public class UpdateApplet extends java.applet.Applet
    implements Runnable {

    private Thread updateThread;
    int updateInterval = 1000;

    public void run(  ) {
        while ( updateThread != null ) {
            try {
                Thread.sleep( updateInterval );
            }
            catch (InterruptedException e ) {
                return;
            }
            repaint(  );
        }
    }

    public void start(  ) {
        if ( updateThread == null ) {
            updateThread = new Thread(this);
            updateThread.start(  );
        }
    }

    public void stop(  ) {
        if ( updateThread != null ) {
            Thread runner = updateThread;
            updateThread = null;  // flag to quit
            runner.interrupt(  );   // wake up if asleep
        }
    }
}