-1
終了JMenuアイテムにヒットしたときにプログラムを終了しようとしています。Jmenuボタンが押されたときにJava用のアクションリスナーを使用してプログラムを終了させる
これは私がアクションリスナーを実行するために使用しているクラスです。
public abstract class ExitListener implements ActionListener {
public void exit(ActionEvent e) {
if (e.getActionCommand().equals("exit")) {
int reply = JOptionPane.showConfirmDialog(null, "Are you sure?", "Quit?", JOptionPane.YES_NO_OPTION);
if (reply == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
}
}
これは私が私のボタンを初期化する方法である:
menuBar = new JMenuBar();
gameMenu = new JMenu("Game");
this.setJMenuBar(menuBar);
menuBar.add(gameMenu);
// Creates the tabs for the Game menu and add's it to the game menu
exit = new JMenuItem("Exit");
gameMenu.add(exit);
私はメニューの終了ボタンを選択すると、何も起こりません。
あなたはどこにいたのかを忘れてしまった:)。 –