本文整理匯總了Java中java.awt.event.KeyListener.keyPressed方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyListener.keyPressed方法的具體用法?Java KeyListener.keyPressed怎麽用?Java KeyListener.keyPressed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.event.KeyListener
的用法示例。
在下文中一共展示了KeyListener.keyPressed方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: processKeyEvent
import java.awt.event.KeyListener; //導入方法依賴的package包/類
@Override
protected void processKeyEvent(KeyEvent e) {
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
if (enter.equals(ks)) {
// Prevent JComponent.processKeyBindings() to be called (it is called from
// JComponent.processKeyEvent() ), notify only registered key listeners
int id = e.getID();
for (KeyListener keyListener : getKeyListeners()) {
switch(id) {
case KeyEvent.KEY_TYPED:
keyListener.keyTyped(e);
break;
case KeyEvent.KEY_PRESSED:
keyListener.keyPressed(e);
break;
case KeyEvent.KEY_RELEASED:
keyListener.keyReleased(e);
break;
}
}
if (!e.isConsumed() && id == KeyEvent.KEY_PRESSED) {
synchronized(listeners) {
List<CellEditorListener> list = new ArrayList<CellEditorListener>(listeners);
for (CellEditorListener listener : list) {
listener.editingStopped(new ChangeEvent(this));
}
}
}
e.consume();
} else {
super.processKeyEvent(e);
}
}
示例2: fireKeyPressed
import java.awt.event.KeyListener; //導入方法依賴的package包/類
/**
* Description of the Method
*
* @param e Description of the Parameter
*/
public void fireKeyPressed(KeyEvent e) {
for (Enumeration<KeyListener> en = listeners.elements(); en.hasMoreElements(); ) {
KeyListener l = en.nextElement();
l.keyPressed(new KeyEvent((java.awt.Component) e.getSource(), KeyEvent.KEY_PRESSED, System.currentTimeMillis(), e.getModifiers(), e.getKeyCode(), e.getKeyChar(), e.getKeyLocation()));
}
}