import java.awt.*; import java.applet.*; // This applet animates a circle moving downwards along a diagonal. // When the circle reaches the bottom, it starts again at the top. public class CircleApplet extends Applet implements Runnable { int extremity = 0; private Thread animator = null; // Called when applet page becomes inactive public void stop( ) { if( animator != null ) animator.stop( ); animator = null; } // Called when applet page becomes active public void start( ) { if( animator == null ) { animator = new Thread( this ); animator.start( ); } } // Implements the Runnable interface public void run( ) { drawCircles( ); } // Infinite loop to draw circle down the main diagonal // by calling paint repeatedly public void drawCircles( ) { for( ; ; ) for( extremity = 0; extremity < 200; extremity++ ) { repaint( ); try { Thread.sleep( 25 ); } catch( InterruptedException e ) { } } } // Draw a circle public void paint( Graphics g ) { g.fillOval( extremity, extremity, 50, 50 ); } }