I have made a Swing application which is rather simple in functionality. However the code which it consist of became rather large and very messy in my opinion. All the swing components and actions is in one file. So for instance if I was to make a even larger application with more functionality the code will be rather hard to go through.
So my question is how to make a good structure of the code. Or if there's a good webpage I can read about it, and if possible some code examples. I have checked Sun's tutorial about Swing, but those a rather simplistic examples they've shown.
UPDATE: I have pondering a while and check for some examples. I don't know if I got the MVC pattern correct. Anyway my idea is to seperate each JFrame to their own class file. Afterward I have one MainFrame which is the main window for the application. From that JFrame I create one instance of each JFrame I have. And call those frame from the MainFrame with Actions. I don't know if this is a good idea. However it makes the code significant easier to read anyway.
Here's an example of how I meant
class Main implements ActionListener {
private JFrame frame = new JFrame();
private JButton button1 = new JButton();
private JPanel panel = new JPanel();
private FirstFrame frame1 = new FirstFrame();
private SecondFrame frame2 = new SecondFrame();
private ThirdFrame frame3 = new ThirdFrame();
public Main() {
button1.addActionListener(this);
}
public createGUI() {
frame.setTitle("Main");
frame.setSize(400,300);
panel.add(button);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
}
public static void main(String args[]) {
new Main().createGUI();
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource() == button1)
{
frame1.enable();
}
}
}