G
G
Gfd2016-12-08 17:32:37
Java
Gfd, 2016-12-08 17:32:37

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;

And the task that now updates the text in lbl_days:
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();

I need to update the text of other labels in the same task.
How can I do that?
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question