From 9c52a48425452ac00b028bda95a43928bbf37a77 Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 12 Jan 2023 18:01:33 -0500 Subject: [PATCH] Added loading FXML view --- pom.xml | 5 +++++ src/main/java/net/metaunix/App.java | 14 ++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 3c63a04..8ae8de8 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,11 @@ javafx-controls 17 + + org.openjfx + javafx-fxml + 17 + diff --git a/src/main/java/net/metaunix/App.java b/src/main/java/net/metaunix/App.java index 53e512a..bf1aadf 100644 --- a/src/main/java/net/metaunix/App.java +++ b/src/main/java/net/metaunix/App.java @@ -1,9 +1,12 @@ package net.metaunix; +import java.io.IOException; + import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Label; -import javafx.scene.layout.StackPane; import javafx.stage.Stage; @@ -13,12 +16,15 @@ import javafx.stage.Stage; public class App extends Application { @Override - public void start(Stage stage) { + public void start(Stage stage) throws IOException { var javaVersion = SystemInfo.javaVersion(); var javafxVersion = SystemInfo.javafxVersion(); var label = new Label("Hello, JavaFX " + javafxVersion + ", running on Java " + javaVersion + "."); - var scene = new Scene(new StackPane(label), 640, 480); + + Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("views/main.fxml")); + var scene = new Scene(root, 640, 480); + stage.setTitle("Acorn Music Player"); stage.setScene(scene); stage.show(); } @@ -27,4 +33,4 @@ public class App extends Application { launch(); } -} \ No newline at end of file +}