单击MenuItem NewGame时.它可以工作,但按F2不会
mntmNewGame.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
int n = JOptionPane.showConfirmDialog(contentPane,"Do you want to play new game ?", "Message!", JOptionPane.OK_CANCEL_OPTION);
}
});
mntmNewGame.addKeyListener(new KeyAdapter() {
public void keyListener(KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_F2)
{
int n = JOptionPane.showConfirmDialog(contentPane,"Do you want to play new game ?", "Message!", JOptionPane.OK_CANCEL_OPTION);
}
}
});
Run Code Online (Sandbox Code Playgroud)