Class Observable
java.lang.Object
java.util.Observable
- Direct Known Subclasses:
AsyncResource
Observable is used to notify a group of Observer objects when a change
occurs. On creation, the set of observers is empty. After a change occurred,
the application can call the
notifyObservers() method. This will
cause the invocation of the update() method of all registered
Observers. The order of invocation is not specified. This implementation will
call the Observers in the order they registered. Subclasses are completely
free in what order they call the update methods.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddObserver(Observer observer) Adds the specified observer to the list of observers.protected voidClears the changed flag for thisObservable.intReturns the number of observers registered to thisObservable.voiddeleteObserver(Observer observer) Removes the specified observer from the list of observers.voidRemoves all observers from the list of observers.booleanReturns the changed flag for thisObservable.voidIfhasChanged()returnstrue, calls theupdate()method for every observer in the list of observers using null as the argument.voidnotifyObservers(Object data) IfhasChanged()returnstrue, calls theupdate()method for every Observer in the list of observers using the specified argument.protected voidSets the changed flag for thisObservable.Methods inherited from class Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()booleanIndicates whether some other object is "equal to" this one.final ClassgetClass()Returns the runtime class of an object.inthashCode()Returns a hash code value for the object.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.toString()Returns a string representation of the object.final voidwait()Causes current thread to wait until another thread invokes the method or the method for this object.final voidwait(long timeout) Causes current thread to wait until either another thread invokes the method or the method for this object, or a specified amount of time has elapsed.final voidwait(long timeout, int nanos) Causes current thread to wait until another thread invokes the method or the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed.
-
Constructor Details
-
Observable
public Observable()Constructs a newObservableobject.
-
-
Method Details
-
addObserver
Adds the specified observer to the list of observers. If it is already registered, it is not added a second time.- Parameters:
observer- the Observer to add.
-
clearChanged
protected void clearChanged()Clears the changed flag for thisObservable. After callingclearChanged(),hasChanged()will returnfalse. -
countObservers
public int countObservers()Returns the number of observers registered to thisObservable.- Returns:
- the number of observers.
-
deleteObserver
Removes the specified observer from the list of observers. Passing null won't do anything.- Parameters:
observer- the observer to remove.
-
deleteObservers
public void deleteObservers()Removes all observers from the list of observers. -
hasChanged
public boolean hasChanged()Returns the changed flag for thisObservable.- Returns:
truewhen the changed flag for thisObservableis set,falseotherwise.
-
notifyObservers
public void notifyObservers()IfhasChanged()returnstrue, calls theupdate()method for every observer in the list of observers using null as the argument. Afterwards, callsclearChanged().Equivalent to calling
notifyObservers(null). -
notifyObservers
IfhasChanged()returnstrue, calls theupdate()method for every Observer in the list of observers using the specified argument. Afterwards callsclearChanged().- Parameters:
data- the argument passed toupdate().
-
setChanged
protected void setChanged()Sets the changed flag for thisObservable. After callingsetChanged(),hasChanged()will returntrue.
-