posted 6 years ago
If you can't use lambda expressions, then get rid of the utility class, and just initialize your actions like this:
If your form needs additional panels, just add them to your frame in the initComponents() method. If you need to be able to reference components in your other methods, add them as fields instead of as local variables. For instance, textArea and fileChooser must be accessed in the openFile() method, so they're private fields of the class; menuBar is only needed inside the initComponents() method, so it's a local variable.
If the panels you want to add become very complex, instead of laying them out in the initComponents() method, make a new class out of them that extend JPanel. You can then lay them out in their own initComponents() method. However, don't expose the components they contain. Instead, design an API for the panel so you can just let them act on part of your model.
Let's say so have a panel that holds some components for application settings:
You see that if we incorporate this SettingsPanel in some form, we don't have to mess with the controls that it contains. We just let it do it's magic, and when we're happy, we call the saveSettings() method on it.