Package java.util |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.util.Observable extends java.lang.Object { // Constructors public Observable(); // Methods public void addObserver(Observer o); protected void clearChanged(); public int countObservers(); public void deleteObserver(Observer o); public void deleteObservers(); public boolean hasChanged(); public void notifyObservers(); public void notifyObservers(Object arg); protected void setChanged(); }
This class represents an observable object, or "data" in the model-view paradigm. It can be subclassed to represent an object that the application wants to have observed.
An observable object can have one or more observers . After an observerable instance changes, an application calling the Observerable's notifyObservers method causes all of its observers to be notified of the change by a call to their update method .
public Observable()The default constructor.
public void addObserver(Observer o)Adds an observer to the set of observers for this object.
Parameter Description o an observer to be added
protected void clearChanged()Indicates that this object has no longer changed, or that it has already notified all of its observers of its most recent change. This method is call automatically by the notifyObservers methods .
public int countObservers()Return Value:
Returns the number of observers of this object.
public void deleteObserver(Observer o)Deletes an observer from the set of observers of this object.
Parameter Description o the observer to be deleted
public void deleteObservers()Clears the observer list so that this object no longer has any observers.
public boolean hasChanged()Determines if this object has changed.
Return Value:
Returns true if the setChanged method has been called more recently than the clearChanged method on this object; false otherwise.
public void notifyObservers()If this object has changed, as indicated by the hasChanged method , then notify all of its observers and then call the clear-Changed method to indicate that this object has no longer changed.
Each observer has its update method called with two arguments: the observable object and null.
public void notifyObservers(Object arg)If this object has changed, as indicated by the hasChanged method , then notify all of its observers and then call the clearChanged method to indicate that this object has no longer changed.
Each observer has its update method called with two arguments: the observable object and the arg argument.
Parameter Description arg any object.
protected void setChanged()Indicates that this object has changed.