As a general rule, should a program with multiple sections create everything at startup or should it wait to create each part when it is actually needed?
My specific case is a Java kiosk-style application that has multiple different sections. Each section is a different JPanel (with different buttons / JTables / JLabels / etc.) that does a specific task. This is an unfinished project that I haven’t touched in a while, but I’m going to complete it and I’m looking at the code and trying to refactor what I think I should have done otherwise.
So far, the program is creating every single JPanel at startup, so whenever an user clicks on one of the button that changes which JPanel is shown, it it loaded instantly since it’s already created. So far, I don’t think it would matter that much performance-wise, but I’d like to know what is standard practice in this case.
I would not load all on start up, as it might make start up slow and also some panels are loaded which are not required. For example you have 4 panels loaded contact, about, pics, and feeds. Suppose you load all 4 at start up, what if user just visited only 2 of them and then close the application. Sometimes it is possible that user wants see only one panel but he has to wait for all panels to load at start up. So I will suggest to load panels as they are required. Load only primary data on frame, and then when user clicks on a button for first time which loads a panel, show a progress bar until that panel is loaded, and from the next time he clicks on button just display the panel with out waiting as it is loaded already by first click.
If your application is getting data from internet then loading all data on start up will also cost extra band width and data charges.