Multiple Page application
I want to design an application that has dozens of pages. I could try and use CardLayout to accomplish this (although for the life of me I couldn't get CardLayout to work when I tried it on another application), however I would prefer not to have all of my pages in memory. Instead, I would prefer to use 1 Frame and create a JPanel for it. Then when I am done with that JPanel, I abandon it, and assign a new JPanel to show the next screen, abandoning that one as well when needed.
Here is the basic logic that I am using:
MainClass
//Create Frame
//Create starting JPanel and assign it to the frame
method ChangePanel(Parameter: JPanel)
//Get component count from the frame and remove existing JPanels from the frame
//Add new JPanel to the frame
StartingJPanelClass
method newpage_actionperformed
//Call MainClass.ChangePanel method (passing new JPanel)
The main concern that I have with this approach is that I don't know if the old pages are truly being abandoned, or if they are still existing in memory. In theory a user could go back and forth between these pages hundreds of times, and if the pages are not being recycled by the garbage collector, memory issues will be a big issue. The reason why I am not sure if they are being abandoned is that the old JPanel calls the MainClass which then removes it from the frame. The JPanel should no longer have a reference to it, however in debug mode, the system briefly returns it to the calling method. Since it has to execute some code after being abandoned, I fear that it is kept in memory.
I am also having a problem with my current implementation (that may or may not be related to it). When I go from Page One to Page Two back to Page One, I see a blank screen when I return to Page One. This is a new instance of Page One. Maybe this is due to the problem that I just described, or maybe it is unrelated.
Message was edited by:
fryet

