Advertisement
Suntechnique

http://stackoverflow.com/questions/9966136/

Aug 27th, 2013
1,853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. import javafx.animation.KeyFrame;
  2. import javafx.animation.Timeline;
  3. import javafx.application.Application;
  4. import javafx.event.ActionEvent;
  5. import javafx.event.EventHandler;
  6. import javafx.scene.Scene;
  7. import javafx.scene.control.Button;
  8. import javafx.scene.layout.StackPane;
  9. import javafx.stage.Stage;
  10. import javafx.util.Duration;
  11.  
  12. public class JavaFXApplication1 extends Application {
  13.  
  14.     @Override
  15.     public void start(Stage primaryStage) {
  16.         Button btn = new Button();
  17.         btn.setText("Say 'Hello World'");
  18.         btn.setOnAction(new EventHandler<ActionEvent>() {
  19.  
  20.             @Override
  21.             public void handle(ActionEvent event) {
  22.                 System.out.println("Hello World!");
  23.             }
  24.         });
  25.  
  26.         StackPane root = new StackPane();
  27.         root.getChildren().add(btn);
  28.  
  29.         Scene scene = new Scene(root, 300, 250);
  30.  
  31.         primaryStage.setTitle("Hello World!");
  32.         primaryStage.setScene(scene);
  33.         primaryStage.show();
  34.  
  35.         Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), new EventHandler<ActionEvent>() {
  36.  
  37.             @Override
  38.             public void handle(ActionEvent event) {
  39.                 System.out.println("this is called every 5 seconds on UI thread");
  40.             }
  41.         }));
  42.         fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
  43.         fiveSecondsWonder.play();
  44.     }
  45.  
  46.  
  47.     public static void main(String[] args) {
  48.         launch(args);
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement