Timer 计时器构造函数未定义
我正在制作一个迷宫相关的游戏,现在我正在处理输入。(W、A、S、D移动) 我的游戏板类有以下几个方面:Timer 计时器构造函数未定义,timer,constructor,actionlistener,Timer,Constructor,Actionlistener,我正在制作一个迷宫相关的游戏,现在我正在处理输入。(W、A、S、D移动) 我的游戏板类有以下几个方面: public class GameBoard extends JPanel implements ActionListener{ private Timer timer; ArrayList<ArrayList<String>> Board; Maze M; Hero H; public GameBoard() {
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();
}
由于这些错误:
构造函数计时器(int,(ActionListener)this)
类型计时器的方法start()未定义
老实说,我不能100%确定计时器是如何工作的,它的用途是什么,尽管我知道它与用户输入有关(以及可以“监听”的频率),这就是为什么每当我键入w、a、s或d时,我的程序都不做任何事,在运行期间。您创建了一个
java.util.Timer
,而不是javax.swing.Timer
timer = new Timer(25, (ActionListener) this);
timer.start();