• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Closing a JFrame

 
Ryan Smith
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, right now I feel completely dumb...all I want to do is create a MenuBar, which I've done, with a ActionListener attached to one of the menu items: a quit button. The actionEvent will be the closing of the JFrame, as I'm sure you've guessed.

After looking through all the API source files for JFrame's methods and inherited methods, I still can't find a method that will just close the window!!

Someone please kick me!
 
Barry Andrews
Ranch Hand
Posts: 523
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dispose()
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to the Swing / JFC / AWT forum...
 
Dmitry Melnik
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.exit(...) will do it
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dispose() if you want to get rid of the JFrame but keep the application alive. System.exit(0) if you want to exit the application loop altogether.

Just thought I would clarify the given solutions a bit.
 
P. Sagdeo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dispose() - Destroys the JFrame completely, frees the resources.

System.exit(int) - Closes the entire program

JFrame.setVisible(false) - Makes the JFrame invisible, make it reappear with a setVisible(true)
[ July 19, 2004: Message edited by: P. Sagdeo ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic