views:

256

answers:

2

I had created a GUI in Netbeans through Netbeans Swing GUI creator. So I just dragged and dropped the Swing Components from the "palette" window and all the code was generated by netbeans.

Now the code is too long to maintain (approx. 10,000 lines). So some experts on SO suggested me to refactor my code.

I can refactor the code that was generated by me but I don't know how to refactor the code generated by the Netbeans as It doesn't allow editing in its generated code.

Any suggestions?

A: 

Well - if the code is generated, I don't see any advantages in refactoring it as long as the tool which generated it can handle it.
The tool (meaning the designer in this case) will "destroy" all your refactoring work as soon as it updates the code.

However, you should split your Control/Window/... into multiple controls - then the code will automatically get shorter and you will be able to maintain your UI more easily.

As a conclusion: Do not refactor the generated code but do refactor your control.

winSharp93
Netbeans refused to handle it by displaying a compiler error - Code too large....
Yatendra Goel
The GUI is desined through Panels... There are lots of Panel in the gui.... How can I write a separate class for each Panel and call it from the main JFrame
Yatendra Goel
As said by Peter Lang: Use JPanels for groups of controls and drag them onto your "Mainframe".
winSharp93
+3  A: 

10.000 lines of code sounds like you have everything in that single class.

Start by splitting your source into Model, View and Control (MVC).


You might also be able to extract some JPanels into separate classes. One way to do this is to create a new JPanel (new file), and cut/paste your compoments from one main panel into that new JPanel. Save and compile your new panel.

Then go back to your main frame, select Beans -> Choose Bean from your Palette and choose the newly created class (com.example.YourPanel for example).

Make sure to have a backup of your application before you try this.

Peter Lang
+1 Note: it's important to set the new JPanel's layout manager to match the original panel or the result of the paste won't look anything like the original.
Devon_C_Miller