【发布时间】:2019-07-24 17:16:49
【问题描述】:
快速示例:我有一个带有两个 ActionListener 的 JButton。它们会以有保证的顺序执行吗?同类型的所有EventListener都一样吗?
JButton b = new JButton();
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println("event 1");
});
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println("event 2");
});
【问题讨论】:
-
IIRC,事件监听器的调用顺序与添加的相反,但我认为这不能保证。如果需要保证,创建一个复合监听器?
-
我通过将
Callable传递给ActionListener解决了我的具体问题
标签: java swing actionlistener event-listener