Methods Summary |
---|
public synchronized void | addObserver(java.util.Observer observer)Adds the specified observer to the list of observers. If it is already
registered, it is not added a second time.
if (observer == null) {
throw new NullPointerException();
}
if (!observers.contains(observer))
observers.addElement(observer);
|
protected synchronized void | clearChanged()Clears the changed flag for this {@code Observable}. After calling
{@code clearChanged()}, {@code hasChanged()} will return {@code false}.
changed = false;
|
public synchronized int | countObservers()Returns the number of observers registered to this {@code Observable}.
return observers.size();
|
public synchronized void | deleteObserver(java.util.Observer observer)Removes the specified observer from the list of observers. Passing null
won't do anything.
observers.removeElement(observer);
|
public synchronized void | deleteObservers()Removes all observers from the list of observers.
observers.setSize(0);
|
public synchronized boolean | hasChanged()Returns the changed flag for this {@code Observable}.
return changed;
|
public void | notifyObservers()If {@code hasChanged()} returns {@code true}, calls the {@code update()}
method for every observer in the list of observers using null as the
argument. Afterwards, calls {@code clearChanged()}.
Equivalent to calling {@code notifyObservers(null)}.
notifyObservers(null);
|
public void | notifyObservers(java.lang.Object data)If {@code hasChanged()} returns {@code true}, calls the {@code update()}
method for every Observer in the list of observers using the specified
argument. Afterwards calls {@code clearChanged()}.
if (hasChanged()) {
// Must clone the vector in case deleteObserver is called
Vector<Observer> clone = (Vector<Observer>)observers.clone();
int size = clone.size();
for (int i = 0; i < size; i++) {
clone.elementAt(i).update(this, data);
}
clearChanged();
}
|
protected synchronized void | setChanged()Sets the changed flag for this {@code Observable}. After calling
{@code setChanged()}, {@code hasChanged()} will return {@code true}.
changed = true;
|