I had developed a Swing GUI which contains 12 JPanels. Initially, all the JPanels code was written in the main JFrame class code. As a result, the code became too long (10,000+ lines).
Now I want to refactor the code to break the code into 13 classes (12 classes each for one JPanel and 1 class for the main JFrame)instead of 1 class carrying all the code.
But I have some confusions which is as follows:
- Initially those 12 JPanels were set on a "Card" JPanel and the layout of the "Card" JPanel was set to CardLayout so that only 1 JPanel out of those 12 JPanels showed at a time based on the button on which use has clicked. Now when I have seperated those 12 JPanels from the MainJForm and implemented each of them into its own class, I think I need to instantiate a corresponding JPanel first whenever a user clicks on the button. So, would it better to do this heavy task on the EDT (Event Dispath Thread). If no, then Will it work to make a instance of the JPanel in SwingWorker thread and pass a ref. to EDT?