I'm trying to use a GridPane
for a Sudoku 9x9 using FXML
.
I'm fairly new in this field so I wanted to ask you guys before proceeding.
I've created a GridPane
9x9 and for now I'm using TextField
in each node to display numbers and enabling the user to write a new number themselves.
My question:
Is it okay to create the 81
TextField's
in pure java code or is there a way to do it efficiently using FXML so I don't split my view (Model-View-Controller) setup up?
Thanks in advance and sorry if my question is unclear, I'm having a hard time explaining it tbh.
Fxml is not the only (and in my opinion not the best way) to use the model view controller pattern in javafx.
The View basically describes how the application / windows / sections look. That can be done with pure fxml, but very often it won't be enough. Especially when you want / need dynamically built content (which in your case you do not really need). So you COULD just add those 9 grid rows and 9 grid columns and add TextFields into them using FXML. However this seems very ineffective, since you could use loops and would remove a lot of time wasters while programming.
You can do that by either using a mix of fxml and code: First load the fxml in your view class and then add to it using code.
Or you could use pure code (my preferred way, since i do not like using fxml if I can't do it in fxml only - and since that is often the case for me i just skip it).
The Model represents your data. Changes in that data will change the view. This is done with observers and binds in the view class.
The Controller manipulates data. Most commonly this is done using user input, but could also be achieved using other events.
However: Keep in mind that MVC is only a very loose pattern and does not define a clear way to do it, since it is not tailored to a specific language / framework. While there are tutorials out there that try to teach how to implement the MVC pattern in JavaFX they all interpret MVC differently and as a result the implementation is also vastly different.
I hope my description of how to structure the View in JavaFX using three different approaches helps you. If not please comment and I'll try to elaborate. :)