import java.awt.*;
import java.applet.*;

public class CircleApplet extends Applet implements Runnable
  {
    int extremity = 0;
    int diameter = 50;
    private volatile Thread animator;

    public void stop()
      {
        animator = null;
      }

    public void start()
      {
        if ( animator == null ) 
          { animator = new Thread(this);
            animator.start();
          }
      }

    public void run()
      { 
        Thread thisThread = Thread.currentThread();
        while (animator == thisThread) 
          {
            try {
                  drawCircles();
                  thisThread.sleep(10000);
                }
            catch (InterruptedException e){} 
          }
      }

    public void drawCircles() throws InterruptedException
      {
        for(;;)
            for( extremity = 0; ; extremity++ )
              {
                repaint();
                Thread.sleep(5);
              }
      }

    private int xAdjust(int X){return X;}   // to make it 'bounce' off the sides
/*      {
        int wide = getSize().width;        
        if ( X > 2*(wide-diameter) ) X = X % (2*(wide-diameter));
        if ( X > wide - diameter ) X = 2*(wide-diameter) - X;
        return X;
      }
*/
    private int yAdjust(int Y){return Y;}   // to make it 'bounce' off the top/bottom
/*      {
        int high = getSize().height;
        if ( Y > 2*(high-diameter) ) Y = Y % (2*(high-diameter));
        if ( Y > high - diameter ) Y = 2*(high-diameter) - Y;
        return Y;
      }
*/
    public void paint( Graphics g )
      { g.drawOval( xAdjust(extremity), yAdjust(extremity), diameter, diameter); }
  }