我正在制作一个与迷宫相关的游戏,现在我正在处理输入。(W、A、S、D移动)。
我的游戏板类有以下方面:
public class GameBoard extends JPanel implements ActionListener{
private Timer timer;
ArrayList<ArrayList<String>> Board;
Maze M;
Hero H;
public GameBoard() {
Game A = new Game();
M = A.getMaze();
H = A.getHero();
Board = A.getMaze().getBoard();
addKeyListener(new AListener());
setFocusable(true);
timer = new Timer(25, (ActionListener) this);
timer.start();
}
但这不会编译:
timer = new Timer(25, (ActionListener) this);
timer.start();
因为这些错误:
构造函数Timer(int,(ActionListener)this);
方法start()对于类型Timer是未定义的。
老实说,我不能100%确定计时器是如何工作的,而且它真的是用来工作的,尽管我知道它与用户输入有关(以及它可以被"监听"的频率),这就是为什么每当我在运行时键入w、a、s或d时,我的程序什么都不做的原因。
您已经创建了java.util.Timer
而不是javax.swing.Timer
。