This content has been marked as final. Show 3 replies
I wouldn't sub-class Stage. I'd stick to having one stage with one scene in it, then put a Pane at the top level (like a StackPane or BorderPane) that acts much like the contentPane does in a Swing JFrame, i.e. add your views to it, swapping them in and out as needed. Each of your views would probably then extend a Pane of some type, and have a controller (and optionally a model) as part of their MVC or MVP design.1 person found this helpful
I'd also recommend using a GUI factory to wire up all your views, controllers and models (and other resources), using dependency injection (which just means you pass in stuff to your class via a setter instead of newing it yourself inside the class - you can use Guice or Spring, but you don't have to it, if you want just code it by hand). This leads to nice modularised code among other things.
My JFX Flow project is based around this idea and provides a framework for making this sort of thing a bit easier: http://www.zenjava.com/jfx-flow/
If you don't want to use the framework directly you can have a look at the 'showcase' codebase for an example of how I would structure an application:
Source code: http://code.google.com/p/jfxflow-samples/source/browse/trunk/showcase/
The JFX Flow source code might be a little less intuitive to follow, but if it helps: http://code.google.com/p/jfxflow/source/browse/
Hope that helps,
I'd try to seperate view and logic into two separate classes. (see various patterns like Presentation Model, MVP, MVC).1 person found this helpful
I subclassed Stage, but only for sub-windows, which popup up, when you click a menu button.
Concerning your "GUI Factory": I wonder how to manage all your views and stages. E.g. if I open a new window (stage) from two different places, I need a manager, that manages this one window instance, because I think it is bad practice to have two instances for the same window.
Is Spring appropriate for this?
You would instantiate all Spring-managed classes, even if you don't need the instance.
Thank you very much for your answers.
I will be using MVC. I heard already of dependency injection too, but only in connection with frameworks you named (Guice, Spring). I didn't know I was using it all the time with the setter methods. Thanks for the clarification of that too!
I will check your project in the next few days, I'm really anxious about some great examples. If any of you could list some other great examples I would be really grateful.