Index (Frames) | Index (No Frames) | Package | Package Tree | Tree
java.util

Class Observable

java.lang.Object
|
+--java.util.Observable


public class Observable

extends Object

This class represents an object which is observable. Other objects may register their intent to be notified when this object changes; and when this object does change, it will trigger the update method of each observer. Note that the notifyObservers() method of this class is unrelated to the notify() of Object.

Authors:See Also:

Constructor Summary

Observable()

Constructs an Observable with zero Observers.

Method Summary

synchronized voidaddObserver(java.util.Observer observer)

Adds an Observer.
synchronized voidclearChanged()

Reset this Observable's state to unchanged.
synchronized intcountObservers()

Returns the number of observers for this object.
synchronized voiddeleteObserver(java.util.Observer victim)

Deletes an Observer of this Observable.
synchronized voiddeleteObservers()

Deletes all Observers of this Observable.
synchronized booleanhasChanged()

True if setChanged has been called more recently than clearChanged.
voidnotifyObservers()

If the Observable has actually changed then tell all Observers about it, then reset state to unchanged.
voidnotifyObservers(java.lang.Object obj)

If the Observable has actually changed then tell all Observers about it, then reset state to unchanged.
synchronized voidsetChanged()

Marks this Observable as having changed.

Constructor Details

Observable

public Observable()

Constructs an Observable with zero Observers.


Method Details

addObserver

public synchronized void addObserver(java.util.Observer observer)

Adds an Observer. If the observer was already added this method does nothing.

Parameters:

Throws:


clearChanged

protected synchronized void clearChanged()

Reset this Observable's state to unchanged. This is called automatically by notifyObservers once all observers have been notified.

See Also:


countObservers

public synchronized int countObservers()

Returns the number of observers for this object.

Returns:


deleteObserver

public synchronized void deleteObserver(java.util.Observer victim)

Deletes an Observer of this Observable.

Parameters:


deleteObservers

public synchronized void deleteObservers()

Deletes all Observers of this Observable.


hasChanged

public synchronized boolean hasChanged()

True if setChanged has been called more recently than clearChanged.

Returns:


notifyObservers

public void notifyObservers()

If the Observable has actually changed then tell all Observers about it, then reset state to unchanged.

See Also:


notifyObservers

public void notifyObservers(java.lang.Object obj)

If the Observable has actually changed then tell all Observers about it, then reset state to unchanged. Note that though the order of notification is unspecified in subclasses, in Observable it is in the order of registration.

Parameters:

See Also:


setChanged

protected synchronized void setChanged()

Marks this Observable as having changed.