Browse Source

add AppController Gui

main
fdai7736 11 months ago
parent
commit
64aff1644b
  1. 18
      src/main/java/de/hsfulda/onses/App.java
  2. 3
      src/main/java/de/hsfulda/onses/Main.java
  3. 29
      src/main/java/de/hsfulda/onses/controllers/AppController.java
  4. 9
      src/main/java/de/hsfulda/onses/controllers/Controller.java
  5. 22
      src/main/java/de/hsfulda/onses/controllers/MainController.java
  6. 22
      src/main/resources/de/hsfulda/onses/views/app.fxml
  7. 14
      src/main/resources/de/hsfulda/onses/views/main.fxml

18
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();
}
}

3
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);
}
}

29
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;
}
}

9
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;
}

22
src/main/java/de/hsfulda/onses/controllers/MainController.java

@ -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();
}
}

22
src/main/resources/de/hsfulda/onses/views/app.fxml

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane prefHeight="585.0" prefWidth="1125.0" xmlns="http://javafx.com/javafx/21" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Label layoutX="473.0" layoutY="121.0" text="Uno Game" AnchorPane.leftAnchor="473.0" AnchorPane.topAnchor="121.0">
<font>
<Font size="34.0" />
</font>
</Label>
<Button fx:id="startGameBtn" layoutX="495.0" layoutY="275.0" mnemonicParsing="false" text="Start Game" AnchorPane.leftAnchor="495.0" AnchorPane.topAnchor="275.0">
<font>
<Font size="19.0" />
</font>
</Button>
</children>
</AnchorPane>

14
src/main/resources/de/hsfulda/onses/views/main.fxml

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<AnchorPane xmlns="http://javafx.com/javafx"
xmlns:fx="http://javafx.com/fxml"
fx:controller="de.hsfulda.onses.controllers.MainController"
prefHeight="400.0" prefWidth="600.0">
</AnchorPane>
Loading…
Cancel
Save