0
在java.awt.event.KeyListener中,如何檢查用戶是否輸入「+」或「 - 」?如何檢查KeyListener輸入?
在java.awt.event.KeyListener中,如何檢查用戶是否輸入「+」或「 - 」?如何檢查KeyListener輸入?
下面是如何做到這一點的代碼實例:
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) {
}
});
您使用什麼語言? – Zevan 2010-12-02 16:49:38