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
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

Using JMenuItem/Exit not working, about is

capp luckett
Ranch Hand

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

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<br /><a href="" target="_blank" rel="nofollow"></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) {
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.

I agree. Here's the link:
subject: Using JMenuItem/Exit not working, about is
It's not a secret anymore!