• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to order a JFrame when closing to open a new JFrame

 
Filip Vero
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I am having this kind of a program where the core menu closes and guides you to another frame.The thing is I want the user when not satisfied and wants to go back to the menu just click the x button up right and dispoce the current JFrame and lead him back to the menu.Is it possible to achieve that by putting a " setDefaultCloseOperation(...) " or how else ? Thanks in advance!
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are using multiple instances of JFrame in your application. That is bad usability.
Always maintain only one JFrame instance. You can add/remove the children at runtime. Just make sure you call revalidate() and repaint() on the parent container (in that order)
When you want some user input (e.g. Confirmation or date of birth) use one of the many convenient methods available in JOptionPane

From what I understood from your question
1) Figure out what the user chose
2) Change the JFrame contents
3) Provide an option to "go back" (e.g. Browser type back button or Back menu or whatever)
4) If the user clicks on back, use the JOptionPane's confirmation method to prompt the user for confirmation
5) If the user confirms, change the JFrame contents to whatever required.
 
Filip Vero
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes pretty much that's what I want, so you suggest me the better solution is to make a single JFrame a "menu" with some kind of listed options for example and if selected an option to repaint the same JFrame instead of opening a new one. I am quite new to this I made some applications using multiple Frames when changing subject , I 'll be glad if you poste some link of example on how exactly to do that, from what I understand is like to make a switch option and depended on menu and then repaint the whole frame.
As for my initial post for my curiosity is it possible to open a new JFrame and setVisible(true) on close from the setDefaultCloseOperation(...)?
Thank you very much for your reply it means a lot to me as I am new to this stuff, much regards and thanks in advance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!