Package java.util Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Observable

Constructors , Methods

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 .


Constructors


Observable

public Observable() 

The default constructor.


Methods


addObserver

public void addObserver(Observer  o) 

Adds an observer to the set of observers for this object.

ParameterDescription
o an observer to be added


clearChanged

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 .


countObservers

public int countObservers() 

Return Value:

Returns the number of observers of this object.


deleteObserver

public void deleteObserver(Observer  o) 

Deletes an observer from the set of observers of this object.

ParameterDescription
o the observer to be deleted


deleteObservers

public void deleteObservers() 

Clears the observer list so that this object no longer has any observers.


hasChanged

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.


notifyObservers

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.


notifyObservers

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.

ParameterDescription
arg any object.


setChanged

protected void setChanged() 

Indicates that this object has changed.



Top© 1996 Sun Microsystems, Inc. All rights reserved.