private class Adapter extends keyAdapter
{
public void keyPressed(KeyEvent e)
{
int vk=e.getKeyCode();
switch(vk);
{
case KeyEvent.VK_0;
actions.doThat("0");
break;
case KeyEvent.VK_1;
actions.doThat("1");
break;
case KeyEvent.VK_2;
actions.doThat("2");
break;
case KeyEvent.VK_3;
actions.doThat("3");
break;
case KeyEvent.VK_4;
actions.doThat("4");
break;
case KeyEvent.VK_5;
actions.doThat("5");
break;
case KeyEvent.VK_6;
actions.doThat("6");
break;
case KeyEvent.VK_7;
actions.doThat("7");
break;
case KeyEvent.VK_8;
actions.doThat("8");
break;
case KeyEvent.VK_9;
actions.doThat("9");
break;
case KeyEvent.VK_PERIOD;
actions.doThat(".");
break;
}
}
}
上面的代码是我覆写的keyPressed方法,执行很正常。但是如果我把这个方法改成覆写keyTyped方法,方法体还是这个方法体,除了方法名改变其他都不改变,那这个方法就执行不正常了!它好像就不会执行switch语句了,这是为什么?
|