FileDocCategorySizeDatePackage
SimulatorSample.javaAPI DocExample2143Tue Jun 03 23:55:32 BST 1997None

SimulatorSample

public class SimulatorSample extends Applet

Fields Summary
Constructors Summary
Methods Summary
public voidinit()

      // use a flow layout, with components centered, and a 20 pixel 
      // separation between components
      setLayout(new FlowLayout(FlowLayout.CENTER, 20, 20));

      // create a temperature
      Temperature t = new Temperature(); 
      
      // create a thermostat     
      Thermostat th = new Thermostat();
      
      // create a cooler
      Cooler c = new Cooler();
      
      // create a boiler
      Boiler b = new Boiler();

      // add the thermostat, cooler, and boiler to the applet      
      add(th);
      add(c);
      add(b);

      // make the thermostat a property change listener of the 
      // temperature object
      t.addPropertyChangeListener(th);
      
      // make the cooler a cooling request listener of the
      // thermostat object
      th.addCoolingRequestListener(c);
      
      // make the boiler a heating request listener of the
      // thermostat object
      th.addHeatingRequestListener(b);
      
      // make the boiler and cooler vetoable change listeners
      // of the thermostat object
      th.addVetoableChangeListener(b);
      th.addVetoableChangeListener(c);

      try
      {
         // make the temperature object a temperature pulse listener
         // of the cooler and boiler objects
         c.addTemperaturePulseListener(t);
         b.addTemperaturePulseListener(t);
      }
      catch (java.util.TooManyListenersException e)
      {
      }
      
      // start the temperature object at 0 degrees
      t.setTemperature(0);