// Chapter 3 -- The second version of class Thermometer
package BeansBook.Simulator;
public class Thermometer
{
// references to the two temperature objects that we are monitoring
protected Temperature theTemperature1;
protected Temperature theTemperature2;
// the temperature change adapter
protected GenericTemperatureAdapter tempAdapter;
// constructor
Thermometer(Temperature temperature1, Temperature temperature2)
{
// save references to the temperature objects
theTemperature1 = temperature1;
theTemperature2 = temperature2;
// create the adapter
tempAdapter = new GenericTemperatureAdapter(this);
try
{
// register the handler methods
tempAdapter.registerEventHandler(theTemperature1, "temperature1Changed");
tempAdapter.registerEventHandler(theTemperature2, "temperature2Changed");
}
catch (NoSuchMethodException e)
{
System.out.println(e);
}
}
// handle changes to Temperature object 1
public void temperature1Changed(TempChangedEvent evt)
{
}
// handle changes to Temperature object 2
public void temperature2Changed(TempChangedEvent evt)
{
}
}