public class EventListenerList extends Object implements Serializable
  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应该改为适当的名称,并将fireFooXxx改为适当的方法名称。 
       对于FooListener接口中的每个通知方法,都应该存在一种方法。 
        警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已经添加到java.beans包中。 请参阅XMLEncoder 。 
| Modifier and Type | Field and Description | 
|---|---|
| protected Object[] | listenerList | 
| Constructor and Description | 
|---|
| EventListenerList() | 
| Modifier and Type | Method and Description | 
|---|---|
| <T extends EventListener> | add(类<T> t, T l)
              将侦听器添加为指定类型的侦听器。 
             | 
| int | getListenerCount()
              返回此侦听器列表的侦听器总数。 
             | 
| int | getListenerCount(类<?> t)
              返回此侦听器列表提供的类型的侦听器总数。 
             | 
| Object[] | getListenerList()
              将事件侦听器列表作为ListenerType侦听器对的数组传回。 
             | 
| <T extends EventListener> | getListeners(类<T> t)
              返回给定类型的所有侦听器的数组。 
             | 
| <T extends EventListener> | remove(类<T> t, T l)
              将侦听器作为指定类型的侦听器删除。 
             | 
| String | toString()
              返回EventListenerList的字符串表示形式。 
             | 
protected transient Object[] listenerList
public Object[] getListenerList()
public <T extends EventListener> T[] getListeners(类<T> t)
ClassCastException - 如果提供的类不能分配给EventListener 
           public int getListenerCount()
public int getListenerCount(类<?> t)
public <T extends EventListener> void add(类<T> t, T l)
t - 要添加的侦听器的类型 
           l - 要添加的侦听器 
           public <T extends EventListener> void remove(类<T> t, T l)
t - 要删除的侦听器的类型 
           l - 要删除的侦听器 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.