// 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 8 -- The Boiler class
package BeansBook.Simulator;
import java.awt.*;
import java.beans.*;
// the Boiler bean class definition
public class Boiler extends TemperatureModifier // subclasses TemperatureModifier
implements HeatingRequestListener, // listens for heating requests
VetoableChangeListener // vetoes property changes
{
// constructor
public Boiler()
{
// a boiler is a temperature modifier that operates at
// 100 degress celsius
super(100.0, "BOILER ON", "BOILER OFF",
Color.red, Color.yellow);
}
// handle a heating request event
public void heatingRequest(ServiceRequestEvent evt)
{
// set the Running property based on the value returned
// by the isStart method from the event
setRunning(evt.isStart());
}
// handle a vetoable change event
public void vetoableChange(PropertyChangeEvent evt)
throws PropertyVetoException
{
// only interested in ComfortTemperature
if (evt.getPropertyName().equals("ComfortTemperature"))
{
// get the proposed temperature
Double d = (Double)evt.getNewValue();
// veto a temperature over 100 degrees Celsius
if (d.doubleValue() > 100.0)
{
throw new PropertyVetoException("Invalid Comfort Temperature", evt);
}
}
}
}
|