在java.awt.event.KeyListener中,如何检查用户是否输入“+”或“ - ”?
答案 0 :(得分:1)
以下是如何执行此操作的代码示例:
TextField field = new TextField();
field.addKeyListener(new KeyListener() {
public void keyTyped(KeyEvent e) {
final char aChar = e.getKeyChar();
if (aChar == '+') {
System.out.println("+ was typed");
}
if (aChar == '-') {
System.out.println("- was typed");
}
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
});