Hey,

I was wondering if someone could help me. I am making a JavaFX application and I have two FXML files. One controller for the main page.

On my homepage I have a button, which I wish that when I click it would load my second FXML file, however I am struggling to implement this, I've been trying since yesterday and my brain is completely fried right now and have no idea. Any help would be appreciated

Main:

public class Main extends Application {

public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("View/HomepageView.fxml"));
primaryStage.setTitle("Room Planner");
primaryStage.setScene(new Scene(root,1050, 650));
primaryStage.show();
}

Controller:


import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import java.net.URL;
import java.util.ResourceBundle;


public class HomepageController implements Initializable {

@FXML
private Button clickme;


/* Method that will be called from the FXML file, to switch scenes*/
public void handleButtonClick() {
clickme.setText("Button pressed");
}


@Override
public void initialize(URL location, ResourceBundle resources) {

}
}

HomeFXML:

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<StackPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="650.0" prefWidth="1050.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="RoomPlanner.Controller.HomepageController">
<children>
<ImageView fitHeight="650.0" fitWidth="1050.0" pickOnBounds="true">
<image>
<Image url="@../Images/Background.jpg" />
</image>
</ImageView>
<Pane prefHeight="200.0" prefWidth="200.0">
<children>
<Text fill="#652121" layoutX="409.0" layoutY="256.0" strokeType="OUTSIDE" strokeWidth="0.0" text="DMU">
<font>
<Font size="74.0" />
</font>
</Text>
<Text fill="WHITE" layoutX="214.0" layoutY="250.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Room">
<font>
<Font size="74.0" />
</font>
</Text>
<Text fill="WHITE" layoutX="578.0" layoutY="256.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Planner" wrappingWidth="270.80859375">
<font>
<Font size="74.0" />
</font>
</Text>
<Text fill="WHITE" layoutX="296.0" layoutY="151.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Welcome To ">
<font>
<Font size="74.0" />
</font>
</Text>
<Button layoutX="400.0" layoutY="339.0" mnemonicParsing="false" fx:id="clickme" onAction="#handleButtonClick" prefHeight="98.0" prefWidth="188.0" text="Click Here To Get Started" />
</children>
</Pane>
</children>
</StackPane>


SecondFXML (which I wish to switch to):

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.shape.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<VBox fx:id="layout1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="493.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<MenuBar>
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Edit">
<items>
<MenuItem mnemonicParsing="false" text="Delete" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<SplitPane dividerPositions="0.33612040133779264" prefHeight="392.0" prefWidth="600.0">
<items>
<AnchorPane prefHeight="467.0" prefWidth="149.0">
<children>
<AnchorPane layoutX="2.0" minHeight="0.0" minWidth="0.0" prefHeight="467.0" prefWidth="199.0">
<children>
<Label layoutX="49.0" layoutY="-6.0" prefHeight="40.0" prefWidth="84.0" text="Objects" textFill="#9a3d3d" underline="true">
<font>
<Font size="23.0" />
</font>
</Label>
</children>
</AnchorPane>
</children>
</AnchorPane>
<ScrollPane prefHeight="373.0" prefWidth="400.0">
<content>
<AnchorPane prefHeight="463.0" prefWidth="390.0">
<children>
<Label layoutX="88.0" layoutY="-3.0" prefHeight="34.0" prefWidth="165.0" text="Floorplan View" textFill="#9a3d3d" underline="true">
<font>
<Font size="23.0" />
</font>
</Label>
</children>
</AnchorPane>
</content>
</ScrollPane>
</items>
</SplitPane>
</children>
</VBox>


Thank You.