![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e3. Implementing a Constrained PropertyA constrained property fires aPropertyChangeEvent whenever its
value is about to be changed. Any listener can veto the event,
thereby preventing the change. This example bean implements a single
constrained integer property called myProperty .
int myProperty; public int getMyProperty() { return myProperty; } public void setMyProperty(int newValue) throws PropertyVetoException { try { vceListeners.fireVetoableChange( "myProperty", new Integer(myProperty), new Integer(newValue)); myProperty = newValue; } catch (PropertyVetoException e) { throw e; } } // Create the listener list. VetoableChangeSupport vceListeners = new VetoableChangeSupport(this); // The listener list wrapper methods. public synchronized void addVetoableChangeListener(VetoableChangeListener listener) { vceListeners.addVetoableChangeListener(listener); } public synchronized void removeVetoableChangeListener(VetoableChangeListener listener) { vceListeners.removeVetoableChangeListener(listener); }
e2. Implementing a Bound Property e4. Instantiating a Bean e5. Listing the Property Names of a Bean e6. Getting and Setting a Property of a Bean
© 2002 Addison-Wesley. |