JClass Elements

PreviousNextIndex

22

Listener List

Features of JCListenerList  Classes  Examples


22.1 Features of JCListenerList

JCListenerList is a class that assists with keeping track of event listeners in a thread-safe manner. The use of static methods on the JCListenerList class prevents any problems from occurring if the list being modified is null. To send events to the listener in the list, simply get the JCListenerListEnumeration of the list and walk through the elements. There is no ordering guarantee.


22.2 Classes

The following is a list of the JCListenerList classes:

JCListenerList

The thread-safe listener list class.

JClistenerListEnumeration

Implements java.util.Enumeration and takes a JCListenerList as its parameter. It defines methods hasMoreElements() and nextElement().


22.3 Methods

The following is a list of the JCListenerList methods:

add()

Adds an element to the list of listeners.

remove()

Removes an element to the list of listeners.

elements()

Returns an Enumeration object.


22.4 Examples

To add a listener using a JCListenerList:

JCListenerList someList = null;
...
public synchronized void addSomeListener(SomeListener l) {
someList = JCListenerList.add(someList, l);
}

To remove a listener:

public synchronized void removeSomeListener(SomeListener l) {
someList = JCListenerList.remove(someList, l);
}

The use of static methods on the JCListenerList class prevents any problems from occurring if the list being modified is null.

To send events to the listener in the list, simply get the Enumeration of the list and walk through the elements. There is no ordering guarantee.


PreviousNextIndex