The Observable class is used to create subclasses that other parts of your program can observe.
When an object subclass undergoes a change, observing classes are notified. Observing classes must implement the Observer interface. Observer interface defines the update( ) method. The update( ) method is called when an observer is notified a change in an observed object.
Observable defines the methods shown in the following.
void addObserver(Observer obj)
Adds obj to the list of objects observing the invoking object.
protected void clearChanged( )
returns the status of the invoking object to "unchanged."
int countObservers( )
Returns the number of objects observing the invoking object.
void deleteObserver(Observer obj)
Removes obj from the list of objects observing the invoking object.
void deleteObservers( )
Removes all observers for the invoking object.
boolean hasChanged( )
Returns true if the invoking object has been modified and false if it has not.
void notifyObservers( )
Notifies all observers of the invoking object that it has changed by calling update( ). A null is passed as the second argument to update( ).
void notifyObservers(Object obj)
Notifies all observers of the invoking object that it has changed by calling update( ). obj is passed as an argument to update( ).
protected void setChanged( )
Called when the invoking object has changed.
If you call notifyObservers( ) with an argument, this object is passed to the observer's update( ) method as its second parameter. Otherwise, null is passed to update( ).