So I'm using javaFX for a school project and I'm trying to change scene in my primary window but I HAVE to use the MVP model so I have to set an event handler to changing the scene inside of the presenter class. I tried doing so by using a variable from my Main class (where I initialize the first scene) and changing the scene from there
public class Main extends Application {
public Stage window = new Stage();
@Override
public void start(Stage primaryStage){
this.window = primaryStage;
Model model = new Model();
mainMenuView view = new mainMenuView();
Presenter presenter = new Presenter(model, view);
Scene mainMenu = new Scene(view);
window.setScene(mainMenu);
window.setTitle("Landen Quiz Main Menu");
window.setWidth(250);
window.setHeight(400);
window.show();
}
public static void main(String[] args) {
launch(args);
}
}
//Main class used to make the main menu (first scene)
public class Presenter {
private Model model;
private view.mainMenuView mainMenuView;
public Presenter(Model model, mainMenuView mainMenuView) {
this.model = model;
this.mainMenuView = mainMenuView;
addEventHandlers();
updateView();
}
private void addEventHandlers(){
mainMenuView.getBtnHelp().setOnAction(e -> {
helpView view = new helpView();
Scene help = new Scene(view);
Main.window.setScene(help);
Main.window.setTitle("Help");
Main.window.show();
});
}
private void updateView(){
//fill mainMenuView with data from model
}
}
//Presenter class used to handel events in GUI
The code isn't fine tuned yet so don't judge. The button works etc but the given error is on the Main.window... in the Presenter "cannot resolve symbol 'Main'"
The presenter is packaged inside a package called 'view' and the Main class is not packaged at all, the code seems to work fine if I take the Presenter out of the package but then it's not correct according to the MVP model.