# Class Observable

Object
Observable

Direct Known Subclasses:
  `Canvas`

public abstract class Observable extends Object
Parent class of all objects for which it is possible to register listeners. This base class does not need to be public; its methods will appear as if they were defined directly in sub-classes.

Since:
  1.5

- ## Constructor Summary

  Constructors
  Modifier
  Constructor
  Description
  `protected`
  `Observable()`
  Creates a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final void`
  `addPropertyChangeListener(String propertyName, PropertyChangeListener listener)`
  Registers a listener for the property of the given name.
  `protected void`
  `firePropertyChange(PropertyChangeEvent event)`
  Notifies all registered listeners that a property changed its value.
  `protected void`
  `firePropertyChange(String propertyName, Object oldValue, Object newValue)`
  Notifies all registered listeners that a property of the given name changed its value.
  `protected final boolean`
  `hasPropertyChangeListener(String propertyName)`
  Returns `true` if the given property has at least one listener.
  `final void`
  `removePropertyChangeListener(String propertyName, PropertyChangeListener listener)`
  Unregisters a property listener.

  ### Methods inherited from class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Observable

    protected Observable()
    Creates a new instance.

- ## Method Details

  - ### addPropertyChangeListener

    public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
    Registers a listener for the property of the given name. The listener will be notified every time that the property of the given name got a new value. If the same listener is registered twice for the same property, then it will be notified twice (this method does not perform duplication checks).
    Parameters:
      `propertyName` - name of the property to listen (should be one of the `*_PROPERTY` constants).
      `listener` - property listener to register.

  - ### removePropertyChangeListener

    public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
    Unregisters a property listener. The given `propertyName` should be the name used during listener registration. If the specified listener is not registered for the named property, then nothing happen. If the listener has been registered twice, then only one registration is removed (one registration will remain).
    Parameters:
      `propertyName` - name of the listened property.
      `listener` - property listener to unregister.

  - ### hasPropertyChangeListener

    protected final boolean hasPropertyChangeListener(String propertyName)
    Returns `true` if the given property has at least one listener.
    Parameters:
      `propertyName` - name of the property to test.
    Returns:
      `true` if the given property has at least one listener.

  - ### firePropertyChange

    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
    Notifies all registered listeners that a property of the given name changed its value. The change event source will be `this`. It is caller responsibility to verify that the old and new values are different (this method does not check for equality).
    Parameters:
      `propertyName` - name of the property that changed its value.
      `oldValue` - the old property value (may be `null`).
      `newValue` - the new property value (may be `null`).
    See Also:
      - `PropertyChangeEvent`
      - `PropertyChangeListener`

  - ### firePropertyChange

    protected void firePropertyChange(PropertyChangeEvent event)
    Notifies all registered listeners that a property changed its value. It is caller responsibility to verify that the event source and property name are valid.
    Parameters:
      `event` - the event to forward. Cannot be null.
    See Also:
      - `PropertyChangeEvent`
      - `PropertyChangeListener`