bla bla first :)
This commit is contained in:
commit
6ad0a2ef29
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
out
|
53
src/timertest/Controller.java
Normal file
53
src/timertest/Controller.java
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
}
|
23
src/timertest/Main.java
Normal file
23
src/timertest/Main.java
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
27
src/timertest/main.fxml
Normal file
27
src/timertest/main.fxml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.geometry.Insets?>
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.layout.ColumnConstraints?>
|
||||||
|
<?import javafx.scene.layout.GridPane?>
|
||||||
|
<?import javafx.scene.layout.RowConstraints?>
|
||||||
|
|
||||||
|
<GridPane alignment="center" hgap="10" vgap="10" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="timertest.Controller">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="countLabel" alignment="CENTER" text="Count: 0" textAlignment="CENTER" GridPane.columnIndex="0" GridPane.columnSpan="2" GridPane.halignment="CENTER" GridPane.hgrow="ALWAYS" GridPane.rowIndex="0" GridPane.valignment="CENTER" />
|
||||||
|
<Button mnemonicParsing="false" onAction="#startTimer" text="Start Timer" GridPane.columnIndex="0" GridPane.rowIndex="1" />
|
||||||
|
<Button mnemonicParsing="false" onAction="#stopTimer" text="Stop Timer" GridPane.columnIndex="1" GridPane.rowIndex="1" />
|
||||||
|
</children>
|
||||||
|
<columnConstraints>
|
||||||
|
<ColumnConstraints />
|
||||||
|
<ColumnConstraints />
|
||||||
|
</columnConstraints>
|
||||||
|
<rowConstraints>
|
||||||
|
<RowConstraints />
|
||||||
|
<RowConstraints />
|
||||||
|
</rowConstraints>
|
||||||
|
<padding>
|
||||||
|
<Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
|
||||||
|
</padding>
|
||||||
|
</GridPane>
|
12
timertest.iml
Normal file
12
timertest.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user