kernel_panic
kernel_panic

Reputation: 119

JavaFX class design

I used Swing for years and now I am moving to JavaFX. Despite many similarities, I'm confused about some topics, such as how to develop larger applications which involve many scenes/stages effectively. In Swing the most used approach was inheritance, e.g by subclassing JPanel class or other Swing components. From what I saw until now, it seems that in JavaFX this is not the common pratice. Although it is possible to subclass Stage and Scene classes, it seems it's not recomended. But I also noticed that, especially in cases of a complex GUI, I end up with my main class (the one containing the start method) becoming an enormous cluster of hundred of lines of code. Such a code seems pretty hard to debug and mantain, but probably I am using a wrong approach. While in Swing this could be avoided in some ways, for example by subclassing some components and reusing them, is there any similar design technique that may help me to break up my JavaFX app in more classes?

Upvotes: 0

Views: 544

Answers (1)

Eli
Eli

Reputation: 76

I would take a look at this tutorial by Oracle which walks you through building a multi-screen javafx application.

The code for this tutorial can be found here Acaicedo GitHub

It follows MVC (Model View Controller) where FXML files are views, associated with unique controllers written in java. This framework adds an extra controller that allows navigation between screens (ie. shifting the show content to a different controller and view).

Upvotes: 1

Related Questions