import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class SpotTest extends Applet {

  /* SpotTest                J M Bishop Aug 2000
   * ========
   *
   * Draws spots of different colours
   *
   * Illustrates simple threads
   */

    int mx, my;
    int radius = 10;
    int boardSize = 200;
    int change;

    public void init() {
      boardSize = getSize().width - 1;
      change = boardSize-radius;

      // creates and starts three threads
      new Spots(Color.red).start();
      new Spots(Color.blue).start();
      new Spots(Color.green).start();
    }


  class Spots extends Thread {

    Color colour;

    // the constructor records the thread's colour
	Spots(Color c) {
	  colour = c;
	}

    // a very simple run method
    public void run () {
      while (true) {
        draw();
        try {
          sleep (500); // millisecs
        }
        catch (InterruptedException e) {
        }
      }
    }

   public void draw() {
     Graphics g = getGraphics();
     g.setColor(colour);
     // calculate a new place for a spot
     // and draw it.
     mx = (int)(Math.random()*1000) % change;
     my = (int)(Math.random()*1000) % change;
     g.fillOval(mx, my, radius, radius);
  }
}
}
