1

I'm looking for some kind of advice for organizing an application.

When you are having a main-menu containing the content-selection, you are pressing a button, the fetching controller has 2 choices: a) change the content where currently the mainmenu is displayed b) create a new scene and switch the stage to that one

What are you using? Is there any kind of best practice?

At the moment I'm prefering a) because I can keep things linke statusbar and such, but is this the "clean" way?

1 Answers1

0

First of all there's some things to consider:
1) Changing scenes will un-link event handlers that you have attached to it, and probably the "statusbar" you mentioned as well.

2) Java is a highly Object-Oriented language and that also means changing between different objects and using polymorphism is a good practice when that is possible.

My experience relates to event handlers as they are often linked to the scene besides when they are linked to specific nodes (buttons), but there are probably other similar concepts to consider. In a project I did I was changing between menu, pause, play and game over display's a lot, but as I was using mainly the same keys and the mouse was hardly involved much I realized I had no benefit from having to create new event handlers for separate Scene objects. Instead I used the Scene.setRoot(); method to change the active display Node/Pane.

However, if your handling is highly different, for instance going from a menu with buttons and text fields into a FPS game where every input has different effects opposed to that of the menu(s) then it would probably be better to have different Overrides of the event handlers in two different Scene objects and instead use the Stage.setScene(); method, thus making handlers act polymorphed* instead of having another set of control structures inside the handler for the CPU to work through for every frame when you're not in the menu.

*I know that when I say polymorphed I am not referring to inheritance polymorphism, but it was the best way I could think of describing the avoidance of extra runtime code in a case you would probably like better performance.

Chexxor
  • 406
  • 6
  • 17