Answer the question
In order to leave comments, you need to log in
How to properly use Task in javafx?
I have 3 labels:
@FXML
private Label lbl_days;
@FXML
private Label lbl_time;
@FXML
private Label lbl_times_of_day;
Task task = new Task<Void>() {
@Override
protected Void call() throws InterruptedException {
boolean running = true;
double timeSleep;
updateMessage("Days: " + (game.getHours() / 24));
while (running) {
updateMessage("Days: " + (game.getHours() / 24));
timeSleep = NORMAL_SPEED / speed;
Thread.sleep((long) timeSleep);
if (isRunning)
game.increaseHours();
}
return null;
}
};
lbl_days.textProperty().bind(task.messageProperty());
new Thread(task).start();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question