1

I want to update timer in simple javafx application. Now I`ve got timer which is not updating. I would like to update label after e.g. 10 seconds. How to do that? Simple code here:

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.scene.Scene;


public class HelloFX extends Application{

    Label label_timer;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        DateFormat dateFormatStart = new SimpleDateFormat("ss");
        Date dateStart = new Date();

        label_timer = new Label("Timer: " + dateFormatStart.format(dateStart));

        /*update time
        DateFormat dateFormatEnd = new SimpleDateFormat("ss");
        Date dateEnd = new Date();

        if(dateFormatStart.format(dateStart) - dateFormatEnd.format(dateEnd) > 10)
        {
            label_timer.setText("Time has stopped");
        }*/

        VBox root = new VBox();
        root.getChildren().add(label_timer);

        Scene scene = new Scene(root, 500, 500);
        stage.setScene(scene);

        stage.show();
    }
}
user2856064
  • 541
  • 1
  • 8
  • 25
  • You can use a [PauseTransition](https://docs.oracle.com/javase/8/javafx/api/javafx/animation/PauseTransition.html) with [setOnFinish](https://docs.oracle.com/javase/8/javafx/api/javafx/animation/Animation.html#setOnFinished-javafx.event.EventHandler-). Many examples on this site. Search. – user1803551 May 21 '17 at 18:48

0 Answers0