vendredi 11 novembre 2016

MVC with JavaFX and FXML

If I have a JavaFX project that uses FXML, how would I structure it to adhere to the Model-View-Controller pattern? This is what I would assume the general structure to be like:

Model - Underlying program (what the GUI is representing).
View - FXML file.
Controller - FXML controller.

The issue with this representation is that the view cannot be notified of the model's changes, as it is simply an FXML file. Should the view be the FXML controller class, and then should I have a main controller class such that the FXML controller gets information from the model, and the main controller handles the action events? In this case, how would the main controller access the JavaFX nodes?

Also, in an MVC pattern, where should the main method be? Right now, It is in my JavaFX Application class, which then does nothing for the remainder of the program. Also, should the JavaFX Application class be part of the MVC pattern, or is it only necessary to initialize the GUI?

Summary of questions (please read the full post though):

  1. How do I structure my JavaFX project which uses FXML to adhere to the MVC pattern? Should the view be the FXML controller class, and then should I have a main controller class such that the FXML controller gets information from the model, and the main controller handles the action events?
  2. In an MVC pattern, where should the main method be?
  3. Should the JavaFX Application class be part of the MVC pattern, or is it only necessary to initialize the GUI?

Aucun commentaire:

Enregistrer un commentaire