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();
}
}