How do I make a JavaBeans property bound?

John Zukowski

You need to implement a pair of methods to maintain list of property change listeners:

public void addPropertyChangeListener(PropertyChangeListener x)
public void removePropertyChangeListener(PropertyChangeListener x)

The utility class PropertyChangeSupport is available to do most of the work for you, managing the list and providing notification support.

The registration support would look like:

private PropertyChangeSupport changes = 
  new PropertyChangeSupport(this);

public void addPropertyChangeListener(
              PropertyChangeListener p) {

public void removePropertyChangeListener(
              PropertyChangeListener p) {

The bound property would then look something like the following:

public void setMood(int mood) {
  int old = this.mood;
  this.mood = mood;
    new Integer(old), new Integer(mood));

And the object interested in the change would need:

public void propertyChange
   (PropertyChangeEvent e) {