Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenuItem Actions  RSS feed

 
Andrew Wood
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok im a bit new to all this. Say i have a JMenu item 'Exit' on my JMenu. How do i program it so that it exits the program?

Cheers
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are a couple of ways. The quick and dirty way:



Obviously you might also want to do things like inquire about unsaved data, prompt for exit confirmation, etc.

You could also create an Action that extends AbstractAction. Then you have an Action object that you can give to any component that can regiter an Action and reuse your ExitAction as many times as you like without re-writing a bunch of code.

Here is a blog of mine from a couple of years ago about using the above method.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!