commit 6ad0a2ef2980a91f46b43b84ce41e8115f949f53 Author: Arti Zirk Date: Mon Apr 2 20:33:17 2018 +0300 bla bla first :) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fca352e --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +out \ No newline at end of file diff --git a/src/timertest/Controller.java b/src/timertest/Controller.java new file mode 100644 index 0000000..0266337 --- /dev/null +++ b/src/timertest/Controller.java @@ -0,0 +1,53 @@ +package timertest; + +import javafx.animation.Animation; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.fxml.FXML; +import javafx.scene.control.Label; +import javafx.util.Duration; + +public class Controller { + + @FXML private Label countLabel; + + private int count = 0; + private int delay = 500; //default delay + private Timeline ticker; + + + public Controller(){ + this.ticker = new Timeline(new KeyFrame( + Duration.millis(delay), + ae -> tick() + ) + ); + this.ticker.setCycleCount(Animation.INDEFINITE); + } + + private void tick() { + this.count++; + this.countLabel.setText("Count: " + this.count); + System.out.println("Tick: " + this.count); + } + + + @FXML + private void startTimer() { + if (this.ticker.getStatus() == Animation.Status.RUNNING) { + this.ticker.setRate(this.ticker.getRate() + 1); // make timeline run faster + System.out.println("FASTER!"); + } else { + this.ticker.play(); + System.out.println("Start"); + } + + } + + @FXML + private void stopTimer() { + System.out.println("Stop"); + this.ticker.setRate(1.0); + this.ticker.stop(); + } +} diff --git a/src/timertest/Main.java b/src/timertest/Main.java new file mode 100644 index 0000000..dc10ea2 --- /dev/null +++ b/src/timertest/Main.java @@ -0,0 +1,23 @@ +package timertest; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class Main extends Application { + + @Override + public void start(Stage primaryStage) throws Exception{ + Parent root = FXMLLoader.load(getClass().getResource("main.fxml")); + primaryStage.setTitle("Hello World"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } + + + public static void main(String[] args) { + launch(args); + } +} diff --git a/src/timertest/main.fxml b/src/timertest/main.fxml new file mode 100644 index 0000000..0e2d37d --- /dev/null +++ b/src/timertest/main.fxml @@ -0,0 +1,27 @@ + + + + + + + + + + + +