Packages This Package Prev Next Index
§3.5 Class Observable
public class java.util.Observable
extends java.lang.Object (I-§1.12)
{
// Constructors
public Observable(); §3.5.1
// Methods
public void addObserver(Observer o); §3.5.2
protected void clearChanged(); §3.5.3
public int countObservers(); §3.5.4
public void deleteObserver(Observer o); §3.5.5
public void deleteObservers(); §3.5.6
public boolean hasChanged(); §3.5.7
public void notifyObservers(); §3.5.8
public void notifyObservers(Object arg); §3.5.9
protected void setChanged(); §3.5.10
}
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 (I-§3.12). After an observerable
instance changes, an application calling the Observerable's notifyObservers method (§3.5.8,
§3.5.9) causes all of its observers to be notified of the change by a call to their update
method (I-§3.12.1).
Observable
public Observable()
- The default constructor.
addObserver
public void addObserver(Observer o)
- Adds an observer to the set of observers for this object.
- Parameters:
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 (§3.5.8, §3.5.9).
countObservers
public int countObservers()
- 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.
- Parameters:
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.
- Returns:
- true if the setChanged method (I-§3.5.10) has been called more recently
than the clearChanged (I-§3.5.3) method on this object; false otherwise.
notifyObservers
public void notifyObservers()
- If this object has changed, as indicated by the hasChanged method
(I-§3.5.7), then notify all of its observers and then call the clear-Changed
method (I-§3.5.3) to indicate that this object has no longer changed.
- Each observer has its update method (I-§3.12.1) 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
(I-§3.5.7), then notify all of its observers and then call the clearChanged
method (I-§3.5.3) to indicate that this object has no longer changed.
- Each observer has its update method (I-§3.12.1) called with two arguments:
the observable object and the arg argument.
- Parameters:
arg
-
any object.
setChanged
protected void setChanged()
- Indicates that this object has changed.
Packages This Package Prev Next Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com