本文整理汇总了Java中java.awt.event.KeyEvent.VK_CLEAR属性的典型用法代码示例。如果您正苦于以下问题:Java KeyEvent.VK_CLEAR属性的具体用法?Java KeyEvent.VK_CLEAR怎么用?Java KeyEvent.VK_CLEAR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.awt.event.KeyEvent
的用法示例。
在下文中一共展示了KeyEvent.VK_CLEAR属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
}
}