views:

92

answers:

2
+1  Q: 

Swing Reuse

I'm writing a Java Desktop App using NetBeans 6.5 and a Swing Patterns that keeps repeating.

Each and every one of my dialogs has a "Save Button" and "Close Button" with different mostly different behaviour behind the Save Button and identical code behind the close button.

How can I reuse this code without copying and pasting and at the same time retain the user of GUI Builder tools for the Inner panel of the dialog box?

+2  A: 

I'm not a netbeans expert, but I'd suggest add a saveAction and closeAction to the dialog box constructor both of which implement Action, and then just get the GUI builder code to execute the appropriate Action.

Nick Fortescue
A: 

I am a C# programmer, but the same concept apply. You can create an abstract class to hold the code that is always the same and an abstract method for each action. This method would be implemented by the class that inherits this new abstract class.

Sergio