PDA

View Full Version : Problem with addSelectionListener() ...



samwells
30 Oct 2008, 4:09 AM
I have a problem with menuItem.addSelectionListener()

See the code below

MenuItem menuItem = new MenuItem("Open");
menuItem.addSelectionListener(new SelectionListener<ComponentEvent>() {

public void componentSelected(ComponentEvent event) {

// doing some operation
System.out.println("Open menuitem selected");

}
This code is working properly the selectionlistener is working
when i click the menuitem I get the print as
Open menuitem selected

But in the below code selectionlistener is not working

MenuItem menuItem = new MenuItem("Open");
menuItem.addSelectionListener(new MenuListener());


// And my MenuListener class is like this

class MenuListener extends SelectionListener<ComponentEvent> {

MenuListener()
}

public void componentSelected(ComponentEvent ce) {
// doing some operation
System.out.println("Open menuitem selected");
}

public void handleEvent(ComponentEvent be) {

}
}

Is this correct way to extend the selection listener class or
we cannot extend selectionlistener class

Thanks in advance

gslender
30 Oct 2008, 5:32 AM
don't override handleEvent, or call super.handleEvent(be);

samwells
30 Oct 2008, 8:16 PM
Thanks for the help its working now

Sam