wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes First steps with Swing: multiple window project. Need help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "First steps with Swing: multiple window project. Need help!" Watch "First steps with Swing: multiple window project. Need help!" New topic
Author

First steps with Swing: multiple window project. Need help!

Emanuele Mazzante
Ranch Hand

Joined: Jan 14, 2014
Posts: 44
    
    1
Hello everyone ,
I recently started to study GUI and Event Handling through the book Core Java Volume I Fundamentals and more I get, the more I feel lost . I tried to do a simple example of a program that I had already done in VB but I can not even figure out where to start with Swing. The author of the book in fact always takes into account a single frame where it does all the work and this is confusing me because I have always been accustomed to draw multiple frames in VB.

Let's consider a simple example of a program that keeps track of the expenses for a family. When I did it in VB I have designed a main window with buttons to access each section of the program as Checking Account, Expense Management, Research, Statistics. Each button closes the main window and load/show a new window. In almost all windows you can access other windows, for example, from Expense Management you can open New Expenditure window (opened in modal mode) etc. .. Closing Expense Management window will load/show the main window, and so on.

Now to make a program in Java using Swing without a GUI builder what is the best approach? For example, I could make a single JPanel for each section and add it in turn to the main window or I could use multiple JFrame. Another idea would be to have a main window always visible (like MDI form in VB) with a menu bar from you can open other windows for each section of the program (i.e. Window-> Show Checking Account Sectiont /-> Show Expense Management Section /-> Show Research Section....).

I also think it is better for the user to have multiple windows open simultaneously but how to deal with this situation in Java/Swing?
For example, if you imagine a main frame where there are buttons (or menu) to access other sections, how I can avoid opening multiple frames of the same section ( I think the user need at most one frame for each section )? It's a proper way to disable/enable the button (or the menu element) when the corresponding frame is opened/closed?

Of course this is just an example, I don't ask for the code to implement it but just the concept of how to handle the graphics for this kind of project. Thanks for patience and the help.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167
    
    8

Multiple main frames is bad usability.

When you face a situation where your UI needs to change, you have (at least) three options
1) Use a card layout to switch the contents of the frame (http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html)
2) Use internal frames. It is the recommended swing MDI solution (http://docs.oracle.com/javase/tutorial/uiswing/components/internalframe.html)
3) Use dialogs (http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html)


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Emanuele Mazzante
Ranch Hand

Joined: Jan 14, 2014
Posts: 44
    
    1
Thank you so much for your interest about my problem. Those links are very helpful! Just one question: why did you write that multiple main frame is bad usability? What are the main disadvantages in making a program that uses them?
 
jQuery in Action, 2nd edition
 
subject: First steps with Swing: multiple window project. Need help!
 
Similar Threads
Hiding a JFrame using a Submit button?
Design question involving GUI and classes.
JTable/GUI Questions
Windows opened from menu items move down and to the right
Creating and showing JFrame from another JFrame