i would like to know how to move data in from one scene in javafx to another. I know that in server side programming like php you use SESSION, but I have no idea of desktop app
Asked
Active
Viewed 461 times
0
-
Try and create a class `Session` that holds the variables you want, and you can either pass it into the new scene or you can just have a `SessionFactory` that you can call statically to retrieve the session. – Orin Aug 25 '16 at 20:03
-
5The question is very broad and there are many possible answers. Probably the most common way this is done in desktop apps is to use a MVC-type architecture and share a single model instance between the controllers (with a one-one correspondence between controllers and views). See e.g. http://stackoverflow.com/questions/32342864/applying-mvc-with-javafx You can also use dependency-injection frameworks (Spring, Guice, or the JavaFX-specific [afterburner.fx](http://afterburner.adam-bien.com/), or others) to inject the model instance into the controllers. – James_D Aug 25 '16 at 20:21
1 Answers
1
Depending on what scope you want to enforce, you can choose one of the following (going from broad to narrow):
A) Use a singleton object that can be accessed globally and allow it to hold any information you require.
B) Use a global/scoped event bus that allows listening for certain events. Attach the scene as a listener to the event bus. The events then carry the information you need to handle the event.
C) Track scenes manually and call methods directly on Scene
instances for the smallest scope.

AlmasB
- 3,377
- 2
- 15
- 17