本文整理汇总了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()));
}
}