0

I have an application, that changes its interface due to users actions (i.e., an installation program). The question is: how to organize switching these pages and building place - build everything in the main constructor, if the class inherits JFrame, or the method that buids up the interface (like createAndShowGui in Oracle's tutorials) - or - provide a method that returns JPanel which represents needed page. Or, like this

class UI extends JFrame {

    private Page1 page1;
    private Page2 page2;
    //...

    public UI() { /* Main UI and switching */ }

    private class Page1 extends JPanel {
        /* ... */
    }

    private class Page2 extends JPanel {
        /* ... */
    }
}
Andrew Vershinin
  • 147
  • 3
  • 3
  • 10
  • The interface organization I had described is wizard-like. The best approaches are using CardLayout or (JInternalFrame, JDesktopPane or JTabbedPane). Close the question, please. – Andrew Vershinin Feb 16 '14 at 16:08
  • From: [first](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657#9554657), [second](http://stackoverflow.com/questions/6476289/replacing-jpanel-with-jpanel-in-a-jframe), [third](http://tips4java.wordpress.com/2008/11/01/card-layout-actions/) – Andrew Vershinin Feb 16 '14 at 16:28

1 Answers1

0

First of all I would use JPanel over JFrame as you probably dont want create a Toplevel GUI Element everytime you switch your panel.

You should use a main panel instead which contains these subpanels (those on which you are planning to switch)

I would recommend splitting it up onto several classes and provide a method which returns the needed JPanel as you switch amongst them.

You could use some Sort of a Factory/Singletonpattern to create/obtain the panels you want to switch to.

So the Mainpanel is handling is accessing the mentioned Factory class to replace the Subpanel you want to display everytime you want to switch to another panel.

hibe
  • 96
  • 8