package animationtimertestapp; import javafx.animation.AnimationTimer; 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; /** * * @author Stanislav Smirnov */ public class AnimationTimerTestApp extends Application { AnimationTimer timer1; public int counter1 = 0; public int counter2 = 0; /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { timer1 = new AnimationTimer() { @Override public void handle(long arg0) { System.out.println("timer1 counter = " + counter1++); } }; timer1.start(); new AnimationTimer() { @Override public void handle(long arg0) { System.out.println("timer2 counter = " + counter2++); } }.start(); final Button btn = new Button(); btn.setText("Start timer1 once again"); btn.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { timer1.start(); } }); StackPane root = new StackPane(); root.getChildren().add(btn); primaryStage.setScene(new Scene(root, 300, 250)); primaryStage.show(); } }