I am developing a software using JavaFX
.
It is a desktop application.
I am new to MVC
, and also JavaFX
; But learn some details by googling.
I follow the steps here, to learn about JavaFX
and also MVC
.
I know that in MVC
, Model
is a POJO
, View
is visualization, and controller acts on both, accept input and convert to commands for view and model.
The model can also have logic to update the controller.
We also for each view, should have a controller.( view-controllers
)
But I have some question; Why in the tutorial
, We create both PersonEditDialog and PersonOverview stage
in the mainApp
?
I mean this :
public void showPersonOverview() {
try {
// Load person overview.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/PersonOverview.fxml"));
AnchorPane personOverview = (AnchorPane) loader.load();
// Set person overview into the center of root layout.
rootLayout.setCenter(personOverview);
// Give the controller access to the main app.
PersonOverviewController controller = loader.getController();
controller.setMainApp(this);
} catch (IOException e) {
e.printStackTrace();
}
}
And this :
public boolean showPersonEditDialog(Person person) {
try {
// Load the fxml file and create a new stage for the popup dialog.
FXMLLoader loader = new FXMLLoader();
loader.setLocation(MainApp.class.getResource("view/PersonEditDialog.fxml"));
AnchorPane page = (AnchorPane) loader.load();
// Create the dialog Stage.
Stage dialogStage = new Stage();
dialogStage.setTitle("Edit Person");
dialogStage.initModality(Modality.WINDOW_MODAL);
dialogStage.initOwner(primaryStage);
Scene scene = new Scene(page);
dialogStage.setScene(scene);
// Set the person into the controller.
PersonEditDialogController controller = loader.getController();
controller.setDialogStage(dialogStage);
controller.setPerson(person);
// Show the dialog and wait until the user closes it
dialogStage.showAndWait();
return controller.isOkClicked();
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
Both are defined and created in the mainApp
class?
Why we did not create the PersonEditDialog stage
and scene
in the PersonOverviewController?
In controllers we should not use new keyword? They just are connectores between view and model?
Im asking about controller rules; for multi stage
and .fxml
software.
My software includes 8 different pages( or more ), Should I create all stages in the mainApp
?
Why should not create new stage
and add the according .fxml
to the scene of that stage in previous step of the application?