'Can Singleton Gui Framework cause a Stack-Overflow? If not, is all loaded data lost between GUI frames?

I've been working on an app that's similar to a dnd character sheet, and I hate working with GUI's. I thought of using something not unlike a MVC pattern for handling the GUI framework (how panels are loaded or hidden), but in my approach I ended up combining it with a Singleton pattern to establish a base class called GUI_Controller that all panels were then loaded onto via method calls. This let me create each new "page" or "sheet" as a separate class, and when I needed it to be "loaded" all I had to do was use the method call within the Singleton GUI_Controller. This approach seems to work, and I like how it makes the framework of the GUI easy to follow. My question is, is this OK? or is this only working for now? I didn't know if the way the control works, if this could lead to a stack overflow error if the "view" kept shifting enough with more and more method calls to classes stacking up. Or if by returning to the Singleton each time, the stack was being kept clean, but resulting in any data "loaded" by one class's call being "erased" and then "re-loaded" when that class's call was called again (ex: clicking on the spells page, going back to character page, then clicking on spells page again).

If so, the data is called via a "Database" class that connects an SQL database. Would it then be best to front load the database before initially moving scope to the Singleton?

The Singleton for GUI_Controller looks like this..

public class GUI_Controller extends JFrame{
   private static GUI_Controller singleton = new GUI_Controller();

private GUI_Controller() {
    initialize();
}

public static GUI_Controller getSingleton() {
    if(singleton == null) {
        singleton = new GUI_Controller();
    }
    return singleton;
}

private JFrame frame;


private void initialize() {
    frame = new JFrame();
    frame.setLocation(100,100);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
    
}


public void setHomePage() {
    HomePage hp = new HomePage();
    
    frame.getContentPane().removeAll();
    frame.getContentPane().add(hp);
    
    frame.pack();
    frame.setVisible(true);
}


public void setSpellsPage() {
    SpellsPage sp = new SpellsPage();
    
    frame.getContentPane().removeAll();
    frame.getContentPane().add(sp);
    
    frame.pack();
    frame.setVisible(true);
}

and other classes access the Singleton in ways like

GUI_Controller gui = GUI_Controller.getSingleton();
    gui.setHomePage();

and

btnViewSpells.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            GUI_Controller gui = GUI_Controller.getSingleton();
            gui.setSpellsPage();
        }
    });

I'll add a note that each class is not a single JPanel, but acts as a "frame" having it's own design and card layout views. I came up with this overall framework to simplify the GUI control, but now I don't know if it's just over-programming.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source