EventListenerList listenerList = new EventListenerList();
FooEvent fooEvent = null;
public void addFooListener(FooListener l) {
listenerList.add(FooListener.class, l);
}
public void removeFooListener(FooListener l) {
listenerList.remove(FooListener.class, l);
}
// Notify all listeners that have registered interest for
// notification on this event type. The event instance
// is lazily created using the parameters passed into
// the fire method.
protected void fireFooXXX() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==FooListener.class) {
// Lazily create the event:
if (fooEvent == null)
fooEvent = new FooEvent(this);
((FooListener)listeners[i+1]).fooXXX(fooEvent);
}
}
}
foo should be changed to the appropriate name, and fireFooXxx to the
appropriate method name. One fire method should exist for each
notification method in the FooListener interface.Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
| Modifier and Type | Field and Description |
|---|---|
| protected transient volatile Object[] | listenerList
The list of ListenerType - Listener pairs |
| private static final Object[] |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public synchronized < the type of T extends EventListener> voidEventListener to add | |
| public int | Returns: an integer count of total number of listenersReturns the total number of listeners for this listener list. |
| public int | Returns: the number of listeners of typetthe type of listeners to count t)Returns the total number of listeners of the supplied type for this listener list. |
| private int | |
| public Object[] | Returns: array of ListenerType-listener pairsPasses back the event listener list as an array of ListenerType-listener pairs. |
| public < the type of T extends EventListener> T[]EventListener to search for | Returns: all of the listeners of the specified type.the type of t)EventListener classes to be returnedReturn an array of all the listeners of the given type. |
| private void | |
| public synchronized < the type of T extends EventListener> voidEventListener | |
| public String | toString()
Overrides java. Returns a string representation of the EventListenerList. |
| private void |
| listenerList | back to summary |
|---|---|
| protected transient volatile Object[] listenerList The list of ListenerType - Listener pairs | |
| NULL_ARRAY | back to summary |
|---|---|
| private static final Object[] NULL_ARRAY | |
| EventListenerList | back to summary |
|---|---|
| public EventListenerList() Constructs a | |
| add | back to summary |
|---|---|
| public synchronized <T extends EventListener> void add(Class<T> t, T l) Adds the listener as a listener of the specified type.
| |
| getListenerCount | back to summary |
|---|---|
| public int getListenerCount() Returns the total number of listeners for this listener list.
| |
| getListenerCount | back to summary |
|---|---|
| public int getListenerCount(Class<?> t) Returns the total number of listeners of the supplied type for this listener list.
| |
| getListenerCount | back to summary |
|---|---|
| private int getListenerCount(Object[] list, Class<?> t) | |
| getListenerList | back to summary |
|---|---|
| public Object[] getListenerList() Passes back the event listener list as an array of ListenerType-listener pairs. Note that for performance reasons, this implementation passes back the actual data structure in which the listener data is stored internally! This method is guaranteed to pass back a non-null array, so that no null-checking is required in fire methods. A zero-length array of Object should be returned if there are currently no listeners. Warning !! Absolutely NO modification of the data contained in this array should be made -- if any such manipulation is necessary, it should be done on a copy of the array returned rather than the array itself.
| |
| getListeners | back to summary |
|---|---|
| public <T extends EventListener> T[] getListeners(Class<T> t) Return an array of all the listeners of the given type.
| |
| readObject | back to summary |
|---|---|
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException
| |
| remove | back to summary |
|---|---|
| public synchronized <T extends EventListener> void remove(Class<T> t, T l) Removes the listener as a listener of the specified type.
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of the EventListenerList. | |
| writeObject | back to summary |
|---|---|
private void writeObject(ObjectOutputStream s) throws IOException
| |