From 64aff1644bafd541b818b020d80c16208c8fd847 Mon Sep 17 00:00:00 2001 From: fdai7736 Date: Tue, 6 Feb 2024 18:53:30 +0100 Subject: [PATCH] add AppController Gui --- src/main/java/de/hsfulda/onses/App.java | 18 ++++++++++++ src/main/java/de/hsfulda/onses/Main.java | 3 +- .../onses/controllers/AppController.java | 29 +++++++++++++++++++ .../hsfulda/onses/controllers/Controller.java | 9 ++++++ .../onses/controllers/MainController.java | 22 -------------- .../resources/de/hsfulda/onses/views/app.fxml | 22 ++++++++++++++ .../de/hsfulda/onses/views/main.fxml | 14 --------- 7 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 src/main/java/de/hsfulda/onses/App.java create mode 100644 src/main/java/de/hsfulda/onses/controllers/AppController.java create mode 100644 src/main/java/de/hsfulda/onses/controllers/Controller.java delete mode 100644 src/main/java/de/hsfulda/onses/controllers/MainController.java create mode 100644 src/main/resources/de/hsfulda/onses/views/app.fxml delete mode 100644 src/main/resources/de/hsfulda/onses/views/main.fxml diff --git a/src/main/java/de/hsfulda/onses/App.java b/src/main/java/de/hsfulda/onses/App.java new file mode 100644 index 0000000..8712287 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/App.java @@ -0,0 +1,18 @@ +package de.hsfulda.onses; + +import de.hsfulda.onses.controllers.AppController; +import de.hsfulda.onses.models.Game; +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class App extends Application { + @Override + public void start(Stage stage) throws Exception { + final AppController appController = new AppController(new Game()); + + stage.setTitle("Onses - Uno Game"); + stage.setScene(new Scene(appController.render())); + stage.show(); + } +} diff --git a/src/main/java/de/hsfulda/onses/Main.java b/src/main/java/de/hsfulda/onses/Main.java index fd78049..8bf1644 100644 --- a/src/main/java/de/hsfulda/onses/Main.java +++ b/src/main/java/de/hsfulda/onses/Main.java @@ -1,10 +1,9 @@ package de.hsfulda.onses; -import de.hsfulda.onses.controllers.MainController; import javafx.application.Application; public class Main { public static void main(String[] args) { - Application.launch(MainController.class); + Application.launch(App.class); } } \ No newline at end of file diff --git a/src/main/java/de/hsfulda/onses/controllers/AppController.java b/src/main/java/de/hsfulda/onses/controllers/AppController.java new file mode 100644 index 0000000..5f8a4cc --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/AppController.java @@ -0,0 +1,29 @@ +package de.hsfulda.onses.controllers; + +import de.hsfulda.onses.Main; +import de.hsfulda.onses.models.Game; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.control.Button; + +import java.io.IOException; +import java.util.Objects; + +public class AppController implements Controller { + + private final Game game; + + public AppController(Game game) { + this.game = game; + } + @Override + public Parent render() throws IOException { + final Parent parent = FXMLLoader.load(Main.class.getResource("views/app.fxml")); + Button button = (Button) parent.lookup("#startGameBtn"); + + button.setOnAction(e -> { + System.out.println("Pressed"); + }); + return parent; + } +} diff --git a/src/main/java/de/hsfulda/onses/controllers/Controller.java b/src/main/java/de/hsfulda/onses/controllers/Controller.java new file mode 100644 index 0000000..3a92766 --- /dev/null +++ b/src/main/java/de/hsfulda/onses/controllers/Controller.java @@ -0,0 +1,9 @@ +package de.hsfulda.onses.controllers; + +import javafx.scene.Parent; + +import java.io.IOException; + +public interface Controller { + Parent render() throws IOException; +} diff --git a/src/main/java/de/hsfulda/onses/controllers/MainController.java b/src/main/java/de/hsfulda/onses/controllers/MainController.java deleted file mode 100644 index ad84d77..0000000 --- a/src/main/java/de/hsfulda/onses/controllers/MainController.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.hsfulda.onses.controllers; - -import de.hsfulda.onses.Main; -import javafx.application.Application; -import javafx.fxml.FXMLLoader; -import javafx.scene.Parent; -import javafx.scene.Scene; -import javafx.stage.Stage; - -import java.io.IOException; -import java.util.Objects; - -public class MainController extends Application { - @Override - public void start(Stage stage) throws IOException { - final Parent parent = FXMLLoader.load(Objects.requireNonNull(Main.class.getResource("views/main.fxml"))); - - stage.setTitle("Onses"); - stage.setScene(new Scene(parent)); - stage.show(); - } -} diff --git a/src/main/resources/de/hsfulda/onses/views/app.fxml b/src/main/resources/de/hsfulda/onses/views/app.fxml new file mode 100644 index 0000000..7facd52 --- /dev/null +++ b/src/main/resources/de/hsfulda/onses/views/app.fxml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + diff --git a/src/main/resources/de/hsfulda/onses/views/main.fxml b/src/main/resources/de/hsfulda/onses/views/main.fxml deleted file mode 100644 index 150a195..0000000 --- a/src/main/resources/de/hsfulda/onses/views/main.fxml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - -