This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Using JMenuItem/Exit not working, about is Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Using JMenuItem/Exit not working, about is" Watch "Using JMenuItem/Exit not working, about is" New topic
Author

Using JMenuItem/Exit not working, about is

capp luckett
Ranch Hand

Joined: Dec 07, 2000
Posts: 33
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



flodin
dan moore
Ranch Hand

Joined: Nov 04, 2001
Posts: 68
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.


dan moore, infomatiq ltd.<br />email dan@infomatiq.co.uk<br /><a href="http://www.infomatiq.co.uk" target="_blank" rel="nofollow">http://www.infomatiq.co.uk</a>
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
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

Joined: Jan 09, 2001
Posts: 1492
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.
 
jQuery in Action, 2nd edition
 
subject: Using JMenuItem/Exit not working, about is
 
Similar Threads
Menu Problems
Swing GUI Interface Question
notepad
MenuBar & Listener Compile errors
Creating one class from another