• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI close issue : press.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  RSS feed

 
rich richy
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
I have a program which displays two buttons and changes the image of one of the buttons on roll over. I am getting an error on my



part, And it looks like this: The method setDefaultCloseOperation(int) is undefined for the type ButtonClass. Even with the exit on close commented out there are more errors, please help.


Main class (with error):




Other class:




Please help,
Thanks.
 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you can only call the set close operation method on a JFrame. The close operation happens when the close button is clicked; the only class which has a suitable close button is a JFrame.

You can compile your code without a top level container, but you can only make it visible if you have a top level container.
 
K. Tsang
Bartender
Posts: 3632
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to close the JFrame using a JButton, a action listener is needed and call System.exit(0)

Using JFrame.EXIT_ON_CLOSE is only for the JFrame.

 
Campbell Ritchie
Sheriff
Posts: 53774
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you want System.exit?

Maybe a save dialogue followed by a call to myFrame.dispose() instead? That way the app saves anything necessary before shutting down.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!