FileDocCategorySizeDatePackage
Temperature.javaAPI DocExample2049Tue Jun 03 21:58:06 BST 1997BeansBook.Simulator

Temperature

public class Temperature extends Object

Fields Summary
protected double
currentTemp
private Vector
tempChangeListeners
Constructors Summary
public Temperature(double startingTemp)


   // the constructors
     
   
      currentTemp = startingTemp;
   
public Temperature()

   
Methods Summary
public synchronized voidaddTempChangeListener(TempChangeListener l)

      // add a listener if it is not already registered
      if (!tempChangeListeners.contains(l))
      {
         tempChangeListeners.addElement(l);
      }
   
protected voidnotifyTemperatureChange()

      // create the event object
      TempChangedEvent evt = new TempChangedEvent(this, currentTemp);

      // make a copy of the listener object vector so that it cannot
      // be changed while we are firing events
      Vector v;
      synchronized(this)
      {
         v = (Vector) tempChangeListeners.clone();
      }

      // fire the event to all listeners
      int cnt = v.size();
      for (int i = 0; i < cnt; i++)
      {
         TempChangeListener client = (TempChangeListener)v.elementAt(i);
         client.tempChanged(evt);
      }
   
public synchronized voidremoveTempChangeListener(TempChangeListener l)

      // remove it if it is registered
      if (tempChangeListeners.contains(l))
      {
         tempChangeListeners.removeElement(l);
      }