implement the start page
This commit is contained in:
parent
e9d91a1986
commit
2652138ddd
@ -8,9 +8,10 @@ import javafx.stage.Stage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class App extends Application {
|
public class App extends Application {
|
||||||
|
// Der gesamte fxml code wurde mithilfe des Github Copilotes generiert
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage stage) throws IOException {
|
public void start(Stage stage) throws IOException {
|
||||||
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("answerText.fxml"));
|
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource("main.fxml"));
|
||||||
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
Scene scene = new Scene(fxmlLoader.load(), 320, 240);
|
||||||
stage.setTitle("Question Catalog");
|
stage.setTitle("Question Catalog");
|
||||||
stage.setScene(scene);
|
stage.setScene(scene);
|
||||||
|
|||||||
23
src/main/java/at/ionas999/questioncatalog/Utils.java
Normal file
23
src/main/java/at/ionas999/questioncatalog/Utils.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package at.ionas999.questioncatalog;
|
||||||
|
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class Utils {
|
||||||
|
public static void switchScenes(String fxmlFileName, Stage stage) throws IOException {
|
||||||
|
|
||||||
|
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxmlFileName));
|
||||||
|
Parent root = fxmlLoader.load();
|
||||||
|
stage.setScene(new Scene(root));
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Stage getStageFromActionEven(ActionEvent actionEvent){
|
||||||
|
return (Stage) ((javafx.scene.Node) actionEvent.getSource()).getScene().getWindow();
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,4 +1,34 @@
|
|||||||
package at.ionas999.questioncatalog.controller;
|
package at.ionas999.questioncatalog.controller;
|
||||||
|
|
||||||
|
import at.ionas999.questioncatalog.Utils;
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class MainController {
|
public class MainController {
|
||||||
|
@FXML
|
||||||
|
private void addNewBtnClick(ActionEvent actionEvent) throws IOException {
|
||||||
|
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||||
|
Utils.switchScenes("upload.fxml", stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void viewBtnClick(ActionEvent actionEvent) throws IOException {
|
||||||
|
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||||
|
Utils.switchScenes("view.fxml", stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void learnBtnClick(ActionEvent actionEvent) throws IOException {
|
||||||
|
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||||
|
Utils.switchScenes("answerText.fxml", stage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void testBtnClick(ActionEvent actionEvent) throws IOException {
|
||||||
|
Stage stage = Utils.getStageFromActionEven(actionEvent);
|
||||||
|
Utils.switchScenes("answerText.fxml", stage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
module at.ionas999.questioncatalog {
|
module at.ionas999.questioncatalog {
|
||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
|
requires java.desktop;
|
||||||
|
|
||||||
opens at.ionas999.questioncatalog to javafx.fxml;
|
opens at.ionas999.questioncatalog to javafx.fxml;
|
||||||
opens at.ionas999.questioncatalog.controller to javafx.fxml; // Add this line
|
opens at.ionas999.questioncatalog.controller to javafx.fxml; // Add this line
|
||||||
|
|||||||
@ -1,16 +1,18 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<?import javafx.geometry.Insets?>
|
|
||||||
<?import javafx.scene.control.Button?>
|
<?import javafx.scene.control.Button?>
|
||||||
<?import javafx.scene.control.Label?>
|
<?import javafx.scene.control.Label?>
|
||||||
<?import javafx.scene.layout.VBox?>
|
<?import javafx.scene.layout.VBox?>
|
||||||
|
|
||||||
<VBox alignment="CENTER" spacing="20.0" xmlns:fx="http://javafx.com/fxml">
|
<VBox alignment="CENTER" spacing="20.0"
|
||||||
|
xmlns="http://javafx.com/javafx"
|
||||||
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
|
fx:controller="at.ionas999.questioncatalog.controller.MainController">
|
||||||
<Label text="Question Catalog" style="-fx-font-size: 24px; -fx-font-weight: bold;" />
|
<Label text="Question Catalog" style="-fx-font-size: 24px; -fx-font-weight: bold;" />
|
||||||
<VBox spacing="10.0" alignment="CENTER">
|
<VBox spacing="10.0" alignment="CENTER">
|
||||||
<Button text="Add New" prefWidth="150" />
|
<Button text="Add New" onAction="#addNewBtnClick" prefWidth="150" />
|
||||||
<Button text="View" prefWidth="149" />
|
<Button text="View" onAction="#viewBtnClick" prefWidth="149" />
|
||||||
<Button text="Learn" prefWidth="150" />
|
<Button text="Learn" onAction="#learnBtnClick" prefWidth="150" />
|
||||||
<Button text="Test" prefWidth="150" />
|
<Button text="Test" onAction="#testBtnClick" prefWidth="150" />
|
||||||
</VBox>
|
</VBox>
|
||||||
</VBox>
|
</VBox>
|
||||||
Loading…
Reference in New Issue
Block a user