我开发了一些桌面应用程序,基于 netbeans GUI 创建者,我遇到了 jButton 行为的奇怪问题,每次单击它时,它都会执行 7 次:
jButton7.addActionListener(new ButtonListener());
class ButtonListener implements ActionListener {
ButtonListener() {
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().equals("pushToTest")) {
System.out.println("Button1 has been clicked");
}
}
}
输出如下:
Button1 has been clicked
Button1 has been clicked
Button1 has been clicked
Button1 has been clicked
Button1 has been clicked
Button1 has been clicked
Button1 has been clicked
只需单击一下。它发生在我所有的按钮上,我无法发布 gui 的代码,它就像 1700 行,甚至没有人会费心阅读它。