0

我正在使用 Java,并且有一种方法可以使用input.next();. 如果用户在键盘上按 ESC,我需要调用另一种方法。是否可以识别 ESC input.next();

4

2 回答 2

1

你需要一个叫做KeyListener的东西

addKeyListener(new KeyListener() {
...
public void keyReleased(KeyEvent e) {
    if (e.getKeyCode() == 27){   //this is the code for the escape key
    //call other method
    }

让我知道我是否可以更详细地指导您。

于 2013-04-07T07:29:37.683 回答
0

我想我有一些有用的链接可以回答你的问题

http://www.thehelper.net/threads/detecting-the-escape-key-press-in-java.136974/

于 2013-04-07T07:29:29.360 回答