This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JMenuItem/Exit not working, about is

 
capp luckett
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • 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


 
dan moore
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • 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.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic