GUI yuuki #5
6 changed files with 93 additions and 0 deletions
33
src/main/java/fr/myny/gui/Gui.java
Normal file
33
src/main/java/fr/myny/gui/Gui.java
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
package fr.myny.gui;
|
||||
|
||||
import javafx.application.Application;
|
||||
import javafx.fxml.FXMLLoader;
|
||||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Gui extends Application {
|
||||
|
||||
private static Scene scene;
|
||||
|
||||
@Override
|
||||
public void start(Stage stage) throws IOException {
|
||||
scene = new Scene(loadFXML("primary"));
|
||||
stage.setScene(scene);
|
||||
stage.show();
|
||||
}
|
||||
|
||||
static void setRoot(String fxml) throws IOException {
|
||||
scene.setRoot(loadFXML(fxml));
|
||||
}
|
||||
|
||||
private static Parent loadFXML(String fxml) throws IOException {
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(Gui.class.getResource(fxml + ".fxml"));
|
||||
return fxmlLoader.load();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
launch();
|
||||
}
|
||||
}
|
||||
13
src/main/java/fr/myny/gui/PrimaryController.java
Normal file
13
src/main/java/fr/myny/gui/PrimaryController.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package fr.myny.gui;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class PrimaryController {
|
||||
|
||||
@FXML
|
||||
private void switchToSecondary() throws IOException {
|
||||
Gui.setRoot("secondary");
|
||||
}
|
||||
}
|
||||
13
src/main/java/fr/myny/gui/SecondaryController.java
Normal file
13
src/main/java/fr/myny/gui/SecondaryController.java
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
package fr.myny.gui;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SecondaryController {
|
||||
|
||||
@FXML
|
||||
private void switchToPrimary() throws IOException {
|
||||
Gui.setRoot("primary");
|
||||
}
|
||||
}
|
||||
7
src/main/java/module-info.java
Normal file
7
src/main/java/module-info.java
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
module fr.myny.gui {
|
||||
requires javafx.controls;
|
||||
requires javafx.fxml;
|
||||
|
||||
opens fr.myny.gui to javafx.fxml;
|
||||
exports fr.myny.gui;
|
||||
}
|
||||
13
src/main/resources/fr/myny/gui/primary.fxml
Normal file
13
src/main/resources/fr/myny/gui/primary.fxml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.geometry.*?>
|
||||
<?import javafx.scene.control.*?>
|
||||
<?import javafx.scene.layout.*?>
|
||||
|
||||
<VBox alignment="CENTER" prefHeight="241.0" prefWidth="397.0" spacing="20.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.myny.gui.PrimaryController">
|
||||
<Label prefHeight="167.0" prefWidth="69.0" text="Primary View" />
|
||||
<Button onAction="#switchToSecondary" prefHeight="109.0" prefWidth="152.0" text="Switch to Secondary View" />
|
||||
<padding>
|
||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
14
src/main/resources/fr/myny/gui/secondary.fxml
Normal file
14
src/main/resources/fr/myny/gui/secondary.fxml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.layout.VBox?>
|
||||
<?import javafx.scene.control.Label?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?import javafx.geometry.Insets?>
|
||||
|
||||
<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fr.myny.gui.SecondaryController">
|
||||
<Label text="Secondary View" />
|
||||
<Button text="Switch to Primary View" onAction="#switchToPrimary" />
|
||||
<padding>
|
||||
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
|
||||
</padding>
|
||||
</VBox>
|
||||
Reference in a new issue