I have a method called changeScene() that I want to be able to call from a separate controller class. For example, when the "settings" button is pressed on the initial scene, the controller class of the fxml file for the initial scene needs to call Main.changeScene("settings.fxml").
Current code of the Main class (no errors):
public class Main extends Application {
private Stage window;
private Scene home, editor;
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
window = stage;
Parent root = FXMLLoader.load(getClass().getResource("/Scenes/MainPage.fxml"));
home = new Scene(root, 640, 400);
window.setTitle("Home");
window.setScene(home);
window.show();
}
//Method I want to be able to call externally
public void changeScene(String fxml) throws Exception{
Parent pane = FXMLLoader.load(
getClass().getResource(fxml));
Scene scene = new Scene(pane);
window.getScene().setRoot(pane);
}
}
My initial thought was to simply add a constructor to the Main class in order to make it initalizeable and call the method that way, but I doubt that's the best solution. Thanks for the help in advance, I'm very knew to JavaFX.