0

所以我有一个系统托盘,我有这个代码。

MenuItem help = new MenuItem ("Help");
help.addActionListener(selectedListener);

然后 selectedListener 的代码是

} else if (pressed.equals("Help")) {
    JOptionPane.showMessageDialog(null, "MESSAGE HERE", "TITLE", 1);
}

问题是,当我在系统托盘中选择项目“帮助”时,messageDialog 会出现,但是当我点击“OK”时会出现另一个,我怎样才能阻止这种情况发生,即使在“OK”之后也只有一个出现被击中?

MenuItem help = new MenuItem("Help");
help.addActionListener(selectedListener);//HERE
//
MenuItem exit = new MenuItem("Exit");
//
takeSS.addActionListener(selectedListener);
hotKey.addActionListener(selectedListener);
version.addActionListener(selectedListener);
changeLog.addActionListener(selectedListener);
help.addActionListener(selectedListener);
exit.addActionListener(selectedListener);
4

1 回答 1

2

您将 -selectedListener添加ActionListener到Help两次 MenuItem

MenuItem help = new MenuItem("Help");
help.addActionListener(selectedListener);//HERE
//
MenuItem exit = new MenuItem("Exit");
//
takeSS.addActionListener(selectedListener);
hotKey.addActionListener(selectedListener);
version.addActionListener(selectedListener);
changeLog.addActionListener(selectedListener);
help.addActionListener(selectedListener);// AND HERE
exit.addActionListener(selectedListener);

删除一个,它将按预期工作。

于 2013-06-29T19:49:01.667 回答