我在代码中找不到什么问题...我尝试通过输入sysout进行调试,但似乎keylistener是罪魁祸首。为什么不注册任何按键?
public class Pong extends Applet implements Runnable, KeyListener {
public void init() {
this.resize(WIDTH, HEIGHT);
this.addKeyListener(this);
p1 = new HumanPaddle(1);
thread = new Thread(this);
thread.start();
}
public void update(Graphics g) {
paint(g);
}
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_UP) {
p1.setUpAccel(true);
}
if(e.getKeyCode() == KeyEvent.VK_DOWN) {
p1.setDownAccel(true);
}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if(key == KeyEvent.VK_UP) {
p1.setUpAccel(false);
}
if(key == KeyEvent.VK_DOWN) {
p1.setDownAccel(false);
}
}
public void keyTyped(KeyEvent e) {
}
}