I'm new to JavaFX and am struggling to create a proper MVC architecture given my current setup. I clicked together a UI using Scene Builder and designated a Controller class.
Startup:
public class Portal extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("PortalUI.fxml"));
stage.setTitle("Portal");
stage.setScene(new Scene(root));
stage.show();
}
}
And the Controller class contains the rest of the code.
public class AccommodationPortalView implements Initializable {
@Override
public void initialize(URL url, ResourceBundle resources) {
// Work here.
}
}
My professor asked that I further separate the concerns and responsibilities of this application. The Controller is not only managing state and talking with the backend, but also updating the View.
My first response was to let the Controller class become the View and create two other classes for the Controller and Model.
However, I'm at a loss at how to connect these pieces. I never need to instantiate the View, so there is no View instance that I can pass to my Controller, for example. Next, I tried making them all singletons and simply letting Controller fetch them at runtime, but that gives me an error.
public class Portal extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("PortalUI.fxml"));
stage.setTitle("Portal");
stage.setScene(new Scene(root));
stage.show();
// Controller gets a View and Model instance in initialize();
// Error: Instantiation and Runtime Exception...
PortalController.INSTANCE.initialize();
}
}
How do I properly set-up an MVC pattern using my current configuration? Is a different architecture required?