Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Sedrick Jefferson
Added: Mar 23, 2018 2:39 PM
Modified: Apr 25, 2018 3:28 PM
Views: 22
AnimationTimer JavaFX
  1. public class MyApp extends Application {
  2.  
  3.     @Override
  4.     public void start(Stage primaryStage) {
  5.         long startTime = System.currentTimeMillis();
  6.         Label timerLabel = new Label();
  7.  
  8.         new AnimationTimer() {
  9.             @Override
  10.             public void handle(long now) {
  11.                 long elapsedMillis = System.currentTimeMillis() - startTime ;
  12.                 timerLabel.setText(Long.toString(elapsedMillis / 1000));
  13.             }
  14.         }.start();
  15.  
  16.         // lay out UI etc etc
  17.  
  18.     }
  19. }