From 384b6240da4e9113c39be8629c0cf12b90fbf5fa Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Thu, 29 Sep 2022 20:08:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=94=AE=E7=9B=98=E7=9A=84?= =?UTF-8?q?=E7=9B=91=E5=90=AC=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/TankFrame.java | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) 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; + } } }