请问AWTEventMulticaster这个类的作用(50分)

  • 主题发起人 主题发起人 Dery
  • 开始时间 开始时间
D

Dery

Unregistered / Unconfirmed
GUEST, unregistred user!
在jdk的文档中有这么一段代码
public myComponent extends Component {
ActionListener actionListener = null;
public synchronized void addActionListener(ActionListener l) {
actionListener = AWTEventMulticaster.add(actionListener, l);
}
public synchronized void removeActionListener(ActionListener l) {
actionListener = AWTEventMulticaster.remove(actionListener, l);
}
public void processEvent(AWTEvent e) {
// when event occurs which causes "action" semantic
if (actionListener != null) {
actionListener.actionPerformed(new ActionEvent());
}
}
我在看别人的代码,比如有人自己写的从Componnet派生出来的Button类中就有这么一段
我大概知道作用好像是把监听器挂到新的组件类中去,但我对
actionListener = AWTEventMulticaster.add(actionListener, l);这句的参数不太明白
为什么还有actionListener既是输入参数也是输出参数?
这个函数的意义谁能说得具体,清楚一些?
 
看看这篇文档,相信对你会有帮助:
http://www.china-pub.com/computers/emook/1118/info.htm
 
对呀,我也看过这篇文章了,里面也有上面我说的这段代码呀
问题是这个函数AWTEventMulticaster.add的作用没搞清楚
从字面上看还用多播的含义呢
谁能说说这个函数背地里都干了些什么?
 
This class will manage an immutable structure consisting of a chain of event listeners and will dispatch events to those listeners.
Because the structure is immutable, it is safe to use this API to add/remove listeners during the process of an event dispatch operation.
actionListener = AWTEventMulticaster.add(actionListener, l);
它得到的是一个事件监听链 类似 actionlistener +=l;
呵呵 不知道理解的对不对
 
是的,我赞同dippa的看法。[:)]
 

Similar threads

后退
顶部