You have created a java.util.Timer
instead of a javax.swing.Timer
.
Timer constructor undefined
-
06-07-2023 - |
Pregunta
I'm making a maze related game and I'm now handling the input. (W, A, S, D to move).
My game board class has the following aspect:
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();
}
But this won't compile:
timer = new Timer(25, (ActionListener) this);
timer.start();
because of these errors:
The constructor Timer(int, (ActionListener) this);
The method start() is undefined for the type Timer.
To be honest, I'm not 100% sure as how the timer works and is really for, even though I know it has to do with the user input (and how often it can be "listened"), which is why my program doesn't do anything whenever I type w, a, s or d, during the runtime.
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow