import java.awt.Graphics;
/** 
 Program: 	Scene class
 Purpose: 	applet that implements a scene of activity
 @author 	john@december.com
 @version 	2.05; 26 Nov 95
 Note:          converted to 1.00 beta
 */

public class Scene extends java.applet.Applet implements Runnable {

   static int sceneWidth  = 500;
   static int sceneHeight = 500;

   private Thread flow;
   private Events theEvents; 
   private boolean done;
   private boolean pause;

   public void init() {
      resize(sceneWidth, sceneHeight);
   }

   public void start() {
      done = false;
      pause = false;
      flow = new Thread(this);
      flow.start();
      theEvents = new Events();
   }

   public void run() {
      try {
          while (!done) {
             Thread.sleep(5);
             if (!pause) repaint();
          }
      }
      catch (InterruptedException e){};
   }

   public void update(Graphics context) {
      while (!done) {
         context.clearRect(0, 0, sceneWidth, sceneHeight);
         theEvents.nextEvent(); 
         theEvents.paint(context); 
         done = (!theEvents.moreEvents());
      }
      context.clearRect(0, 0, sceneWidth, sceneHeight);
      stop();
   }

   public boolean mouseDown(java.awt.Event evt, int x, int y) { 
      pause = !pause;
      return (true);
   }

   public void stop() {
      done = true;
      theEvents.stop();
      flow.stop();
   }
}
