Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javafx.animation.KeyFrame;
- import javafx.animation.Timeline;
- import javafx.application.Application;
- import javafx.event.ActionEvent;
- import javafx.event.EventHandler;
- import javafx.scene.Scene;
- import javafx.scene.control.Button;
- import javafx.scene.layout.StackPane;
- import javafx.stage.Stage;
- import javafx.util.Duration;
- public class JavaFXApplication1 extends Application {
- @Override
- public void start(Stage primaryStage) {
- Button btn = new Button();
- btn.setText("Say 'Hello World'");
- btn.setOnAction(new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- System.out.println("Hello World!");
- }
- });
- StackPane root = new StackPane();
- root.getChildren().add(btn);
- Scene scene = new Scene(root, 300, 250);
- primaryStage.setTitle("Hello World!");
- primaryStage.setScene(scene);
- primaryStage.show();
- Timeline fiveSecondsWonder = new Timeline(new KeyFrame(Duration.seconds(5), new EventHandler<ActionEvent>() {
- @Override
- public void handle(ActionEvent event) {
- System.out.println("this is called every 5 seconds on UI thread");
- }
- }));
- fiveSecondsWonder.setCycleCount(Timeline.INDEFINITE);
- fiveSecondsWonder.play();
- }
- public static void main(String[] args) {
- launch(args);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement