/*
 * TLApplet.java 97/10/20
 * Copyright (c) 1997, B. F. Caviness
 *
 * This software may be copied/modified for any non-commercial educational
 * use.
 * It is found in the directory
 * $CLASSHOME/exer-solutions/tlApplet/withPedLight/synchronized/
 */

/**
 * This applet is to be used with animated, synchronized traffic and
 * pedestrian light classes of the same date.  This code is found in
 * the directory
 * <tt>$CLASSHOME/exer-solutions/tlApplet/withPedLight/synchronized/</tt>.
 * To use these two classes in an applet, it is only necessary to first
 * create a new pedestrian light, a new traffic light with a reference to
 * the associated pedestrian light and to set the durations of the three
 * colors of lights in the traffic light (or use the defaults).  No run
 * method is needed in the applet to animate or synchronize the lights.
 * This is done by the run methods of the two classes.
 */

import java.applet.*;		// for Class Applet
import java.awt.*;		// for Color

public class TLApplet extends Applet{
   TrafficLight trafficLight;
   PedestrianLight pedLight;
   Thread tlThread, plThread;

   public void init() {
      System.out.println("TLApplet's init() method called");
      pedLight = new PedestrianLight( "Don't Walk" );
      trafficLight = new TrafficLight( pedLight,Color.red );
      setLayout( new BorderLayout() );
      add( "Center", trafficLight );
      add( "South", pedLight );
      tlThread = new Thread( trafficLight );
      plThread = new Thread( pedLight );
      tlThread.start();
      plThread.start();
   }

   /**************************************
    * Now for the applet's methods
    **************************************/

   public void start() {
       System.out.println("TLApplet's start() method called");
       tlThread.resume();
       plThread.resume();
   }

   public void stop() {
      System.out.println("TLApplet's stop() method called");
      tlThread.suspend();	// Suspend thread when Applet is stopped.
      plThread.suspend();
   }

   public void destroy() {
      System.out.println("TLApplet's destroy() method called");
      tlThread = null;
      plThread = null;
   }
}
