diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..07cbd92 --- /dev/null +++ b/.classpath @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..2d3cbb0 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + FxStoppuhr + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.xtext.ui.shared.xtextBuilder + + + + + + org.eclipse.xtext.ui.shared.xtextNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b76ee8e --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=9 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=9 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=9 diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..ddf9c65 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +/main/ diff --git a/build.fxbuild b/build.fxbuild new file mode 100644 index 0000000..2f5d2b8 --- /dev/null +++ b/build.fxbuild @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..fd6fb5a --- /dev/null +++ b/pom.xml @@ -0,0 +1,89 @@ + + 4.0.0 + 0.0.1 + Stoppuhr + + + + + org.openjfx + javafx-controls + 11 + + + + org.openjfx + javafx-fxml + 11 + + + + com.jfoenix + jfoenix + 9.0.8 + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 11 + 11 + + true + true + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + + + java + + + + + main.java.com.Stoppuhr.application.Main + + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.1 + + Stoppuhr + true + + + com.Stoppuhr.application.JavaFX11Main + + + + + + package + + shade + + + + + + + Stoppuhr + application + diff --git a/src/main/java/com/Stoppuhr/application/JavaFX11Main.java b/src/main/java/com/Stoppuhr/application/JavaFX11Main.java new file mode 100644 index 0000000..63b8531 --- /dev/null +++ b/src/main/java/com/Stoppuhr/application/JavaFX11Main.java @@ -0,0 +1,10 @@ +package main.java.com.Stoppuhr.application; + +public class JavaFX11Main +{ + + public static void main(String[] args) + { + Main.main(args); + } +} \ No newline at end of file diff --git a/src/main/java/com/Stoppuhr/application/Main.java b/src/main/java/com/Stoppuhr/application/Main.java new file mode 100644 index 0000000..1fc97ab --- /dev/null +++ b/src/main/java/com/Stoppuhr/application/Main.java @@ -0,0 +1,238 @@ +package main.java.com.Stoppuhr.application; + + +import javafx.animation.Animation; +import javafx.animation.KeyFrame; +import javafx.animation.Timeline; +import javafx.animation.Animation.Status; +import javafx.application.Application; +import javafx.event.ActionEvent; +import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.stage.Stage; +import javafx.util.Duration; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.control.MenuItem; +import javafx.scene.layout.AnchorPane; + +/** + * Praktikum OOSE SS 2018 Aufgabenblatt 3, Aufgabe 4 + * + * @author [Hendrik Schutter] + */ + +public class Main extends Application +{ + + @FXML + private Label zeitAnzeige; + + @FXML + private AnchorPane mainAnchorpane; + + @FXML + private MenuItem menuItemStart; + + @FXML + private MenuItem menuItemReset; + + @FXML + private MenuItem menuItemClose; + + @FXML + private MenuItem menuItemHilfe; + + @FXML + private Button startStopButton; + + @FXML + private Button resetButton; + + private static Timeline timeline; + + private int min = 0; + + private int sec = 0; + + private int mil = 0; + + private static boolean timer = true; + + @Override + public void start(Stage primaryStage) + { + try { + FXMLLoader loader = new FXMLLoader( + getClass().getResource("/fxml/MainWindow.fxml")); + AnchorPane pane = loader.load(); + primaryStage.setTitle("Stoppuhr"); + Scene scene = new Scene(pane); + /** + * alle event listener mit fxml-loader + * + */ + scene.getStylesheets().add( + Main.class.getResource("/css/application.css").toExternalForm()); + primaryStage.setScene(scene); + primaryStage.show(); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + @FXML + public void menuItemStartAction(ActionEvent event) + { + startOrStopCounting(); + } + + @FXML + public void menuItemResetAction(ActionEvent event) + { + resetTime(); + updateTimeLabel(); + } + + @FXML + public void menuItemCloseAction(ActionEvent event) + { + System.exit(0); + } + + @FXML + public void menuItemHilfeAction(ActionEvent event) + { + Alert alert = new Alert(AlertType.INFORMATION); + alert.setTitle("Information"); + alert.setHeaderText("Praktikum OOSE SS 2018 Aufgabenblatt 3, Aufgabe 4"); + alert.setContentText("Author: Hendrik Schutter - 183129"); + alert.showAndWait(); + } + + @FXML + public void startStopButtonAction(ActionEvent event) + { + startOrStopCounting(); + } + + @FXML + public void resetButtonAction(ActionEvent event) + { + resetTime(); + updateTimeLabel(); + } + + public static void main(String[] args) + { + launch(args); + } + + /** + * Aktualisiert die Zeitanzeige. + */ + private void updateTimeLabel() + { + if (mil > 99) { + sec = sec + 1; + mil = 0; + } + + if (sec > 59) { + min = min + 1; + sec = 0; + } + + String timeMin = Integer.toString(min); + String timeSec = Integer.toString(sec); + String timeMil = Integer.toString(mil); + + if (mil < 10) { + timeMil = "0" + Integer.toString(mil); + } + + if (sec < 10) { + timeSec = "0" + Integer.toString(sec); + } + + if (min < 10) { + timeMin = "0" + Integer.toString(min); + } + + String time = timeMin + ":" + timeSec + ":" + timeMil; + + zeitAnzeige.setText(time); + + // System.out.println("Die Zeit: " + time); + + // Text im Label neu setzen + } + + /** + * Diese Methode startet bzw. stoppt die Uhr. Sie soll beim Drücken des + * Start/Stop-Buttons aufgerufen werden. + */ + private void startOrStopCounting() + { + // Je nachdem, ob die Uhr gerade läuft oder nicht: + // Timer pausieren oder starten, dann + + if (timer) { + timeline = new Timeline(new KeyFrame(Duration.millis(10), event -> { + incrementTime(); // update time + })); + timeline.setCycleCount(Animation.INDEFINITE); + timer = false; + } + if (timeline.getStatus() == Status.STOPPED + || timeline.getStatus() == Status.PAUSED) { + timeline.play(); + startStopButton.setText("Stop"); + menuItemStart.setText("Stop"); + } else { + timeline.stop(); + startStopButton.setText("Start"); + menuItemStart.setText("Start"); + } + + } + + /** + * Diese Methode setzt die Uhr auf 00:00:00 zurück. Sie soll beim Drücken des + * Start/Stop-Buttons aufgerufen werden. + */ + private void resetTime() + { + min = 0; + sec = 0; + mil = 0; + } + + /** + * Diese Methode erhöht die Zeit um eine hunderstel Sekunde. Sie muss vom + * Timer (s. Methode 'start') jede hundertstel Sekunde aufgerufen werden. + */ + private void incrementTime() + { + // Zeitvariable(n) erhöhen + // und Anzeige aktualisieren + + mil = mil + 1; + updateTimeLabel(); + } + +} + +class InnerClassHandler implements EventHandler +{ + @Override + public void handle(ActionEvent event) + { + System.out.println("text"); + } +} diff --git a/src/main/resources/css/application.css b/src/main/resources/css/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/src/main/resources/css/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/src/main/resources/fxml/MainWindow.fxml b/src/main/resources/fxml/MainWindow.fxml new file mode 100644 index 0000000..dc37c13 --- /dev/null +++ b/src/main/resources/fxml/MainWindow.fxml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/target/classes/MainWindow.fxml b/target/classes/MainWindow.fxml new file mode 100644 index 0000000..818db8b --- /dev/null +++ b/target/classes/MainWindow.fxml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/target/classes/application.css b/target/classes/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/target/classes/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/target/classes/css/application.css b/target/classes/css/application.css new file mode 100644 index 0000000..83d6f33 --- /dev/null +++ b/target/classes/css/application.css @@ -0,0 +1 @@ +/* JavaFX CSS - Leave this comment until you have at least create one rule which uses -fx-Property */ \ No newline at end of file diff --git a/target/classes/fxml/MainWindow.fxml b/target/classes/fxml/MainWindow.fxml new file mode 100644 index 0000000..dc37c13 --- /dev/null +++ b/target/classes/fxml/MainWindow.fxml @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..ff427ad --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,3 @@ +main/java/com/Stoppuhr/application/JavaFX11Main.class +main/java/com/Stoppuhr/application/Main.class +main/java/com/Stoppuhr/application/InnerClassHandler.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..ce88cce --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1 @@ +/home/hendrik/eclipse-workspace/Java/FxStoppuhr/src/main/java/Stoppuhr.java