Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

GUI not closing

 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so i wrote my GUI window and then a second one. so when the user clicks the button but when the user clicks the window stays open heres my code.

 
Rob Camick
Ranch Hand
Posts: 2539
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats because you created 2 frames.

StartupWindow is a frame which you make visible when you create it.

Then in the constructor of StartupWindow you create a second JFrame.

StartupWindow should not be a frame because you didn't change the behaviour of a JFrame. So your code should be something like:



Once you do this your code won't compile because you are trying to reference methods of the StartupWindow wihich no longer exists.

So you need to change these methods to reference the frame you created. For example:



 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok so i have this but it still dose not work i have this

 
Randall Twede
Ranch Hand
Posts: 4363
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i hate to say it but your english is not very good.
ok so i wrote my GUI window and then a second one. so when the user clicks the button but when the user clicks the window stays open
means nothing to me.
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are a few different Gui's that do different things some times theirs a few open and other times i just need the main one on at some points but i can get my different GUI's to close. make more sense?
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not tying to be a annoyance on the forums but im trying to learn GUIs so some help would be nice. i build this program that has some clicks that go to diffrent questions but when i call the new windows the old one dose not close.
 
Tony Docherty
Bartender
Posts: 2941
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry but it's hard for people to help you if you don't clearly explain what your code is supposed to do and what it is actually doing.

I've had a quick look at your code and a problem I can see is (and I've no idea if it's the one causing your problem because like Rob I'm unclear as to what the issue is), in the actionPerformed() method you are creating a new JFrame and overwriting the value in jf and so any future calls to jf's methods will be on the new instance and not the instance that is currently displayed.
 
James Eman
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok yea that works thank you. thank you again
 
Tony Docherty
Bartender
Posts: 2941
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My pleasure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic