FileDocCategorySizeDatePackage
Temperature.javaAPI DocExample2848Tue Jun 03 23:55:18 BST 1997BeansBook.Simulator

Temperature

public class Temperature extends Object implements TemperaturePulseListener, Serializable

Fields Summary
protected PropertyChangeSupport
boundSupport
protected double
theTemperature
Constructors Summary
public Temperature()

   
   // constructor
    
   
      // construct the support object
         boundSupport = new PropertyChangeSupport(this);
   
Methods Summary
public voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)

      // defer to the support object
      boundSupport.addPropertyChangeListener(l);
   
public doublegetTemperature()

      return theTemperature;
   
public voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)

      // defer to the support object
      boundSupport.removePropertyChangeListener(l);
   
public voidsetTemperature(double t)

      // don't bother if the value didn't change
      if (t == theTemperature)
         return;

      // save the old value
      Double old = new Double(theTemperature);
      
      // save the new value         
      theTemperature = t;
      
      // fire the property change event
      boundSupport.firePropertyChange("Temperature", old, new Double(t));
   
public voidtemperaturePulse(TemperaturePulseEvent evt)

      // get the pulse temperature
      double p = evt.getPulseTemperature();
      
      // get the current temp
      double c = getTemperature();
      
      // if the pulse temperature is greater than the current temperature
      if (p > c)
      {
         // only change if the difference is more than 1
         if ((p - c) >= 1.0)
         { 
            // add 1 to the current temperature
            setTemperature(c + 1.0);
         }
      }
      else if (p < c) // pulse less than the current temperature
      {
         // only change if the difference is more than 1
         if ((c - p) >= 1.0)
         {
            // subtract 1 from the current temperature
            setTemperature(c - 1.0);
         }
      }