本文整理匯總了Java中java.awt.event.KeyEvent.VK_CANCEL屬性的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.VK_CANCEL屬性的具體用法?Java KeyEvent.VK_CANCEL怎麽用?Java KeyEvent.VK_CANCEL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.VK_CANCEL屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextForKeyChar
public static String getTextForKeyChar(char keyChar) {
int keycode;
switch (keyChar) {
case ' ':
keycode = KeyEvent.VK_SPACE;
break;
case '\b':
keycode = KeyEvent.VK_BACK_SPACE;
break;
case '\t':
keycode = KeyEvent.VK_TAB;
break;
case '\n':
keycode = KeyEvent.VK_ENTER;
break;
case '\u0018':
keycode = KeyEvent.VK_CANCEL;
break;
case '\u001b':
keycode = KeyEvent.VK_ESCAPE;
break;
case '\u007f':
keycode = KeyEvent.VK_DELETE;
break;
default:
return "" + keyChar;
}
return (String) keyCodes.get(Integer.valueOf(keycode));
}
示例2: keyPressed
@Override
public void keyPressed(KeyEvent e) {
int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK;
if ((e.getModifiersEx() & ign) != 0)
return;
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
case KeyEvent.VK_KP_LEFT:
if (pos > 0)
--pos;
break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_KP_RIGHT:
if (pos < curText.length())
++pos;
break;
case KeyEvent.VK_HOME:
pos = 0;
break;
case KeyEvent.VK_END:
pos = curText.length();
break;
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_CANCEL:
cancelEditing();
break;
case KeyEvent.VK_CLEAR:
curText = "";
pos = 0;
break;
case KeyEvent.VK_ENTER:
stopEditing();
break;
case KeyEvent.VK_BACK_SPACE:
if (pos > 0) {
curText = curText.substring(0, pos - 1) + curText.substring(pos);
--pos;
field.setText(curText);
}
break;
case KeyEvent.VK_DELETE:
if (pos < curText.length()) {
curText = curText.substring(0, pos) + curText.substring(pos + 1);
field.setText(curText);
}
break;
case KeyEvent.VK_INSERT:
case KeyEvent.VK_COPY:
case KeyEvent.VK_CUT:
case KeyEvent.VK_PASTE:
// TODO: enhance label editing
break;
default:
; // ignore
}
}