FileDocCategorySizeDatePackage
Thermometer.javaAPI DocExample933Tue Jun 03 21:58:24 BST 1997BeansBook.Simulator

Thermometer.java

// This example is from the book Developing Java Beans by Robert Englander. 
// Copyright (c) 1997 O'Reilly & Associates.
// You may study, use, modify, and distribute this example for any purpose.
// This example is provided WITHOUT WARRANTY either expressed or implied.

// Chapter 2 -- The Thermometer class

package BeansBook.Simulator;

public class Thermometer implements TempChangeListener
{
   // a reference to the temperature object that we are monitoring
   protected Temperature theTemperature;

   Thermometer(Temperature temperature)
   {
      theTemperature = temperature;

      // register for temperature change events
      theTemperature. addTempChangeListener(this);
   }

   // handle the temperature change events
   public void tempChanged(TempChangedEvent evt)
   {
      // do something with the temperature that we can retrieve
      // by calling evt.getTemperature()
   }
}