File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes close window when new one opens Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "close window when new one opens" Watch "close window when new one opens" New topic
Author

close window when new one opens

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
I've made a menu screen that has a series of buttons that, when clicked on, open up a new window. I want the menu screen to close when a button is clicked and the new window pops up but I can't figure out how to get it to work. Its not a big deal, just a little nuisance thats drivin' me nuts. Any ideas?
Ben Zung
Ranch Hand

Joined: Mar 25, 2004
Posts: 109
I don't know which part you could not figure out. Do you have some code at all? If you can post them you may get more help.

Good Luck.
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Here's a login screen, which takes in a user ID and last name and checks it against a text file. After the user has logged in a menu pops up with various buttons that, when clicked on, open up new forms. When the user logs in I want the login screen to no longer be visible after the menu screen pops up. Part of the problem may be that I have setVisible for the screen in its own seperate run method, do you think that I should change my code so it works in the action listener? I was avoiding that at all possible costs as the frames for all of the windows I've made are coded like that.


[ March 20, 2006: Message edited by: Brandi Love ]
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Here's the code for the menu screen as well, I'm not sure whether I need to code it into the login screen or menu screen...

Ben Zung
Ranch Hand

Joined: Mar 25, 2004
Posts: 109
Here is a little quick way to do what you wanted.
Move the JFrame variable in your run method in LoginScreen up to be a class level variable(don't forget to say static). And after you verified the 4-digit id, in front of run(new MenuScreen()...) add this code
frame.setVisible(false);
this ought to get rid of the login screen.

Good luck.
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
I made those changes, but now when I click the logon button it, for lack of a better word, melded with the menu screen to make this:



Here's the changes I made to the code, bolded...

Ben Zung
Ranch Hand

Joined: Mar 25, 2004
Posts: 109
Forgot to mention, instead of

call it static way

should get rid of the overlap. And if not
try add

to force a paint.
[ March 20, 2006: Message edited by: Ben Zung ]
Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Yay, that fixed it! Thanks Ben!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: close window when new one opens