FileDocCategorySizeDatePackage
VisualTemperature.javaAPI DocExample3163Wed Jun 04 00:39:20 BST 1997BeansBook.Simulator

VisualTemperature

public class VisualTemperature extends Panel implements TemperaturePulseListener, Serializable

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

   
   // 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 voiddirectTemperaturePulse(double pulse)

      // emulate a regular temperature pulse
      temperaturePulse(new TemperaturePulseEvent(null, pulse));
   
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);
         }
      }