public void run() {
setSize(700,700);
setGame();
}
public GObject drawPlayer() {
GOval player = new GOval(getWidth()/2,getHeight()/2,10,10);
player.setFilled(true);
player.setFillColor(Color.red);
return player;
}
public void keyPressed(KeyEvent e) {
switch(e.getKeyCode()) {
case KeyEvent.VK_UP: Player.move(0, -10);break;
case KeyEvent.VK_DOWN: Player.move(0, 10);break;
case KeyEvent.VK_LEFT: Player.move(-10, 0);break;
case KeyEvent.VK_RIGHT: Player.move(10, 0);break;
}
}
public GRect object;
public void setGame() {
setObject();
GObject Player = drawPlayer();
add(Player);
addKeyListeners();
}
然后我为播放器创建椭圆,我添加KeyListeners 方法来检测键当我运行时我不能使用箭头键来移动播放器对象??我的代码有什么问题???