import javafx.application.Application; import javafx.scene.layout.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.stage.Stage; import javafx.scene.text.*; import java.time.LocalTime; public class Klokke extends Application { Text tekst = new Text(naa()); @Override public void start(Stage stage) { VBox root = new VBox(); root.getChildren().add(tekst); stage.setScene(new Scene(root, 200, 200)); stage.show(); new Thread(() -> { boolean slutt = false; while (!slutt) { tekst.setText(naa()); try { Thread.sleep(1000); } catch (InterruptedException e) { slutt = true; } } }).start(); } private static String naa() { LocalTime t = LocalTime.now(); return String.format("%02d:%02d:%02d", t.getHour(), t.getMinute(), t.getSecond()); } }