import java.awt.* ;
import java.applet.* ;

public class Anima extends Applet
  implements Runnable {

  private volatile boolean runFlag;
  private int x, y, height, width;
  private Image img;
  private Graphics g;
  private Thread t = null;
  private Color nightColor = new Color (0, 0, 102);
  private Color moonColor  = new Color (204, 204, 255);

  public void init() {
    Dimension d = getSize();
    width = d.width;
    height = d.height;
    img = createImage (width, height);
    g=img.getGraphics();
    x = width/2;
    y = height/2;
  }

  public void start() {
    if (t == null)
      {
      t = new Thread (this);
      t.start();
      }
  }
  public void stop() {
    if (t != null)
      {
      runFlag=false; // or: t.stop();
      t=null;
      }
  }

  public void run () {
    runFlag=true;
    while (runFlag) {
      g.setColor (nightColor);
      g.fillRect(0,0,width,height);
      g.setColor (moonColor);
      g.fillArc(x, y-25, 50, 50, 270, 180);
      repaint();
      x = x+ 2;
      if (x > width+50 ) {
        x = -50;
      }
      try { Thread.sleep(100); }
      catch (InterruptedException e) {}
    }
  }

  public void update (Graphics g) {
    paint(g);
  }

  public void paint (Graphics g) {
    if (img != null) {
      g.drawImage(img,0,0,null);
    }
  }

}

