所以我有一个系统托盘,我有这个代码。
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);
答案 0 :(得分:2)
您将ActionListener
- selectedListener 两次添加到帮助 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);
删除一个,它将按预期工作。