定时器构造函数未定义

时间:2014-04-19 20:41:42

标签: 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() {
        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时什么都不做。

1 个答案:

答案 0 :(得分:0)

您已创建java.util.Timer而不是javax.swing.Timer