From 2ce070f34af997183859d50ff9634085f0ce546c Mon Sep 17 00:00:00 2001 From: Lukas Reichwein Date: Wed, 19 Jun 2019 18:22:37 +0200 Subject: [PATCH 001/146] Added BasicGui --- .../com/ugsbo/gui/BasicGuiController.java | 45 +++++++++++++++ src/main/java/com/ugsbo/gui/MainApp.java | 57 ++++++++++++++++++- .../resources/com/ugsbo/gui/BasicGui.fxml | 41 +++++++++++++ src/main/resources/com/ugsbo/gui/styles.css | 4 ++ 4 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/ugsbo/gui/BasicGuiController.java create mode 100644 src/main/resources/com/ugsbo/gui/BasicGui.fxml create mode 100644 src/main/resources/com/ugsbo/gui/styles.css diff --git a/src/main/java/com/ugsbo/gui/BasicGuiController.java b/src/main/java/com/ugsbo/gui/BasicGuiController.java new file mode 100644 index 0000000..6a313df --- /dev/null +++ b/src/main/java/com/ugsbo/gui/BasicGuiController.java @@ -0,0 +1,45 @@ +package com.ugsbo.gui; + +import javafx.fxml.FXML; +import javafx.scene.control.*; + +public class BasicGuiController { + + //Hier werden die fx:id Attribute verknuepft. + @FXML + private Button app1; //Fuer ToDoManager. + @FXML + private Button app2; + @FXML + private Button app3; + @FXML + private Button app4; + + /** + * Konstructor is called before initialize() + */ + public BasicGuiController() { + //Setup of some Fields could be defined here. + } + + /** + * Initializes the controller class. This method is automatically called after + * the fxml file has been loaded. + */ + @FXML + public void initialize() { + app1.setOnMouseClicked((event) -> { + //MainApp.startToDoMainGui(); + System.out.println(event); + }); + app2.setOnMouseClicked((event) -> { + System.out.println(event); + }); + app3.setOnMouseClicked((event) -> { + System.out.println(event); + }); + app4.setOnMouseClicked((event) -> { + System.out.println(event); + }); + } +} \ No newline at end of file diff --git a/src/main/java/com/ugsbo/gui/MainApp.java b/src/main/java/com/ugsbo/gui/MainApp.java index 4a0dafe..7da8f02 100644 --- a/src/main/java/com/ugsbo/gui/MainApp.java +++ b/src/main/java/com/ugsbo/gui/MainApp.java @@ -1,8 +1,61 @@ package com.ugsbo.gui; -public class MainApp { +import java.io.IOException; +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.*; +import javafx.stage.Stage; + +/** + * Runs the main Application and handles the loading of an FXML file. + */ +public class MainApp extends Application { + + /** + * The main() method is ignored in correctly deployed JavaFX application. main() + * serves only as fallback in case the application can not be launched through + * deployment artifacts, e.g., in IDEs with limited FX support. NetBeans ignores + * main(). + * + * @param args the command line arguments + */ public static void main(String[] args) { - System.out.println("HelloWorld!"); + launch(args); + } + + /** + * Starts the Main GUI, will be called from JavaFx. + */ + @Override + public void start(Stage stage) { + createStageFromFXML(stage, "BasicGui"); + } + + /** + * Loades the FXML file and the Default CSS. + * + * @param stage The Stage will be passed over from fxml + * @param fxmlFileName Only the Filename of the fxml file wich sould be loaded + */ + private void createStageFromFXML(Stage stage, String fxmlFileName) { + // Gettring the FXML loader to load the File. + FXMLLoader loader = new FXMLLoader(getClass().getResource(fxmlFileName + ".fxml")); + Parent root; + // trying to load the FXML and CSS file for the GUI with the fxmlFileName. + try { + root = loader.load(); + Scene basicGUI = new Scene(root); + basicGUI.getStylesheets().add(getClass().getResource("styles.css").toExternalForm()); + // Setting the Title of the + stage.setTitle("Ultra geile Studenten Benutzeroberfläche"); + // set Resizeable to false, in oder to block resizeing though the User. + stage.setResizable(false); + stage.setScene(basicGUI); + } catch (IOException e) { + System.out.println(".FXML or .css File can not be found."); + e.printStackTrace(); + } + stage.show(); } } diff --git a/src/main/resources/com/ugsbo/gui/BasicGui.fxml b/src/main/resources/com/ugsbo/gui/BasicGui.fxml new file mode 100644 index 0000000..0fcd44d --- /dev/null +++ b/src/main/resources/com/ugsbo/gui/BasicGui.fxml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + +