用到了观察者模式~
在JButton的父类AbstractButton中我找到了这样的代码
protected void fireActionPerformed(ActionEvent event) {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
ActionEvent e = null;
// 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==ActionListener.class) {
// Lazily create the event:
if (e == null) {
String actionCommand = event.getActionCommand();
if(actionCommand == null) {
actionCommand = getActionCommand();
}
e = new ActionEvent(AbstractButton.this,
ActionEvent.ACTION_PERFORMED,
actionCommand,
event.getWhen(),
event.getModifiers());
}
((ActionListener)listeners[i+1]).actionPerformed(e);//这里遍历了所有的监听
}
}
我的猜测,传入的参数 event应该就是鼠标点击的事件 ,这个fireActionPerformed 方法就是点击后调用的~
具体的调用我Debug了下,发现调用还是比较复杂的~我对Gui不了解,具体怎么触发的鼠标点击事件,没有耐心去找了。。。
|