• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using JMenuItem/Exit not working, about is

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI:
I have a problem where the "about" menuitem functions but
Not the "exit" under File. Could someone give me a clue as
to what is missing. Not sure whether actionPerform is right
for the listeners. There are 4 class files but I am showing
just the 2 important ones.
thanks, its the final project.
capp


 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Capp,
looked a while and can't see anything obvious, does menu listener get called when you click File-Exit? if so, looks like e.getSource() is not as expected. you might try System.out.println of e.getSource(), but more generally could do with breaking down handler into smaller chunks (e.g. smaller multiple if/else calling doFileOpen(), doFileExit() etc.). it should make it easier to read / debug.
hope that helps.
cheers, dan.
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is exactly why I like to use anonymous classes for listeners. But if you are going to lump all listeners together at least make seperate methods to handle the work.
if (something) {
performSomething()
}
Keeps your code cleaner that way.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Capp,
Without your Final class, I can't see what you are doing wrong. Normally you should work with buttons and menuitems by setting the ActionCommand and using it inside the listener. This will avoid having to keep your class variables non-private. Remember to be fully encapsulated class variables should be private and all other classes should use accessors/setters to change them.
Example:

Regards,
Manfred.
 
This tiny ad is wafer thin:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic