【发布时间】:2015-08-04 06:05:03
【问题描述】:
当点击 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);
}
}
});
【问题讨论】:
标签: java swing keylistener