Developing Java Beans reject an unacceptable change to

Developing Java Beans reject an unacceptable change to the FontSize property before any of the listening objects are ever notified. The class java.beans.VetoableChangeSupport is provided to make managing constrained properties easier. You can either inherit from this class or use an instance of it. The public methods of VetoableChangeSupport are shown here: public class java.beans.VetoableChangeSupportimplements java.io.Serializable { // construct the objectpublic VetoableChangeSupport(Object source); // add a vetoable change listener public synchronized void addVetoableChangeListener(VetoableChangeListener l); // fire a vetoable change event to any listeners public void fireVetoableChange(String propertyName, Object oldValue, Object newValue) throws java.beans.PropertyVetoException; // remove a vetoable change listenerpublic synchronized voidremoveVetoableChangeListener(VetoableChangeListener l); } The fireVetoableChange() method performs a valuable service. It fires the VetoableChangeEvent to all registered listeners, and if any of them veto the change it refires the event to all listeners to revert them to the old property value and then rethrows the java.beans.PropertyVetoException. This can be a real convenience, as we will see in the next example. Let’s look again at our Thermometer class. If an instance of this class is used to control a heating device, we might have a property of the Thermometer named MinimumTemperature. This is a read/write property that is used to set the temperature threshold that will trigger the turning on and off of the connected heating device. When the temperature drops 1 degree below this threshold, the heater will be turned on. The heater will be shut off when the temperature reaches the MinimumTemperature value. Let’s constrain the MinimumTemperature value to be no less than 10 degrees Celsius (50 degrees Fahrenheit), the minimum value that the Thermometer class itself will allow. The relevant additions to the Thermometer class are shown next. package BeansBook.Simulator; import java.beans.*; public class Thermometer implements PropertyChangeListener { // the minimum temperature threshold value defaults to// 15 degrees Celsiusprotected double minTemperature = 15.0; // the support object for constrained properties protected VetoableChangeSupport constrainedHandler; // constructor Thermometer(Temperature temperature) { page 62
Note: If you are looking for high quality webhost to host and run your jsp application check Vision jsp hosting services

Comments are closed.