2010-12-02 129 views

回答

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) { 
     } 
    });