2

This is my first post to this forum, so if I screw something up, please let me know.

I have been using the information provided on this site for a good few months at this point to help me with various questions, so I thank you all for it the help!

Anyway, enough fluff and on to the question: I am currently writing my first company-use program in the Java language and I have run into something for which I haven't given much thought until last week.

Currently, I have created a program that uses two separate swing-type GUIs - one to log in a user and one that I am dubbing "the main GUI." As with any language, there are multiple ways to achieve this and after much thinking about what the best way to do it is, I was wondering if anyone with experience had any insight as to the best practice for implementing multiple GUIs.

Right now, I have the login GUI's action listener creating the main GUI object, but I do not think this is the best way to go about it (I'm sure some of the more seasoned Java programmers are probably cringing at the thought of creating a GUI object from an action listener - it's like I can feel them wanting to smack the back of my head!).

So, to be direct - I have thought of about 3 different ways to acheive the objective, from recycling the JFrame to creating the GUI objects in main and setting visibility, and am wondering what the best practice (industry standard) is. Can anyone point me in the right direction?

I have posted this question to another group and was completely ignored. I am beginning to think there may not be a real answer to the question, but would like to try you experts at Stack Overflow before I give up. What are your thoughts? How have you implemented them in the past? Is better to instantiate them in main and manipulate visibility? While I have found posts that speak of best practices for creating a GUI, I haven't seen much that speaks of multiple GUIs in the same program. Thanks for your time!

jsun1973
  • 31
  • 3
  • *"best practice for implementing multiple GUIs."* Look for ideas in [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Apr 19 '12 at 05:07
  • Thanks, Andrew. I didn't think to look for use of multiple JFrames. My noob is showing... :) – jsun1973 Apr 20 '12 at 13:21

1 Answers1

1

I believe what you did with the actionListener was overall okay to do, considering the first thing that appears is the log in screen. I've been in the same spot as you have and I've done 2 different things:

1) I created them both and just changed the visibility. I linked the frames to my main frame, so I could grab data from all the other frames. So you could use this method if you'd like to use the data from the log in screen on your main JFrame.

2) I used an actionListener to wait for the user to log in successfully, and on succession, the main GUI would be created.

My opinion: I would go with method 1. It will allow you to use any of the JFrames to gather any necessary data. Also, it will provide the user with what GUIs were designed for, quick and easy access to whatever the project (or product) was created for. People don't want to spend time waiting for each new JFrame they want to access load. It would be best to load the program all at once, so that it looks as if they GUI is operating at a fast speed, and provides results almost instantly.

Anthony
  • 496
  • 3
  • 9