Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refactor Netbeans generated GUI code?

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?

like image 487
Yatendra Avatar asked Dec 23 '22 06:12

Yatendra


1 Answers

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.

like image 115
Peter Lang Avatar answered Jan 12 '23 03:01

Peter Lang