• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Emanuele Mazzante
Ranch Hand
Posts: 54
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11096
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Emanuele Mazzante
Ranch Hand
Posts: 54
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic