2

I have been through java docs, java online courses/presentations on youtube and threads on stackoverflow, but never found an easy and great method to interact between different views on javafx applications. And most of the times examples have been showing only one view at the time.

Researches I have done so far is that a fxml file needs a controller to be hooked with, and if you have more fxml files, the proper way would be to get a controller to each of them.

What I still do not understand is the Abstract Parent class. Why is it created an instance of that in the javafx fxml application at the beginning on start method? Do I need to instantiate it again when I am trying to load a new fxml file? Same goes to the FXMLLoader. What exactly is fx:root construct? Other researches I have observed are that you do not necessarily need multiple stages or scenes to load a new fxml file.

What I am trying to achieve is an lightweight and simple looking chat application in javafx. Right now I am working on the Client application and planning to apply 3 fxml files: login, chat and submit new user. I do not know wether I should create new stage and scene, only new scene or just replacing the fxml file, one at the time, inside the current stage & scene? Basically I want login to point me to chat screen, new user to create acc screen and both of them to point me back to login screen.

The part I am struggling with is the FXMLLoad part and who is parent and children to who or are all of them parent? And how to organize the files. I have uploaded two images to show you how I am thinking and what I want to approach. Is it really possible to load a new fxml at time to current stage & scene, based on ActionEvent? If yes, how can i approach that?

I hope I made it clear.

javafxarchitecture of my application javafxarchitecture of my application

loginscreen loginscreen

Cœur
  • 37,241
  • 25
  • 195
  • 267
samsebamse
  • 77
  • 8
  • "What I still do not understand is the Abstract Parent class." I don't know what this means. Are you referring to the `Application` class? And this question: "I do not know wether I should create new stage and scene, only new scene or just replacing the fxml file, one at the time, inside the current stage & scene?" surely just depends on what you want the user experience to be (i.e. one window, or multiple windows). I don't think anyone can answer that for you. – James_D Feb 22 '17 at 19:26
  • "What exactly is fx:root construct? " is answered [here](http://stackoverflow.com/questions/23600926/how-to-understand-and-use-fxroot-in-javafx). – James_D Feb 22 '17 at 19:29
  • 1
    OK, you have lots of questions, that's great. I suggest you may want to break down and ask one question per question and perhaps supply some sample code in some of the questions to better explain what you mean. – jewelsea Feb 22 '17 at 19:29
  • Related: [Changing Scenes in JavaFX](http://stackoverflow.com/questions/36463725/changing-scenes-in-javafx) and [Loading new fxml in the same scene](http://stackoverflow.com/questions/18619394/loading-new-fxml-in-the-same-scene). – jewelsea Feb 22 '17 at 19:34
  • Related to "never found an easy and great method to interact between different views" - you can [pass data to the different controllers](http://stackoverflow.com/questions/14187963/passing-parameters-javafx-fxml/14190310#14190310). I like to use a MVC approach ([one example of how](http://stackoverflow.com/questions/32342864/applying-mvc-with-javafx)), where I pass a shared model instance to each controller, and the model is implemented using observable properties. – James_D Feb 22 '17 at 19:37

0 Answers0