private int seconds = 5;
private SpeedMathGo speedMathGo;
Timer timeRemaining = new Timer();
TimerTask task = new TimerTask() {
public void run() {
if (speedMathGo.turn == "X") {
seconds = 5;
seconds --;
if (seconds == 0) {
speedMathGo.turn = "O";
}
}
timerLabel.setText("Time remaining: " + seconds + "s");
if (speedMathGo.turn == "O") {
seconds = 5;
seconds --;
if (seconds == 0) {
speedMathGo.turn = "X";
}
}
timerLabel.setText("Time remaining: " + seconds + "s");
}
};
public void time() {
timeRemaining.scheduleAtFixedRate(task, 5000, 1000);
}
This portion of the code is to act as a timer, giving 5s for X and O to answer the math problem on their respective turn. Why is there no countdown when this is ran? If more parts of the class are required, I will be happy to provide.