diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java index 588e466..5ccbb4e 100644 --- a/src/com/msb/TankFrame.java +++ b/src/com/msb/TankFrame.java @@ -45,16 +45,60 @@ public class TankFrame extends Frame { //这里使用内部内的原因是,只有TankFrame用到 class MyKeyListener extends KeyAdapter { + + private boolean bL = false; + private boolean bR = false; + private boolean bU = false; + private boolean bD = false; + @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); /*x += 10; repaint();*/ + switch (e.getKeyCode()) { + case KeyEvent.VK_LEFT : { + bL = true; + break; + } + case KeyEvent.VK_RIGHT : { + bR = true; + break; + } + case KeyEvent.VK_UP : { + bU = true; + break; + } + case KeyEvent.VK_DOWN : { + bD = true; + break; + } + default: break; + } } @Override public void keyReleased(KeyEvent e) { super.keyReleased(e); + switch (e.getKeyCode()) { + case KeyEvent.VK_LEFT : { + bL = false; + break; + } + case KeyEvent.VK_RIGHT : { + bR = false; + break; + } + case KeyEvent.VK_UP : { + bU = false; + break; + } + case KeyEvent.VK_DOWN : { + bD = false; + break; + } + default: break; + } } }