PDA

View Full Version : about handling menuItem event



cqiao
26 Jun 2008, 4:42 AM
tow piece os code:
A:
menuItem1.addListener(Events.OnClick, new Listener<MenuEvent>(){

public void handleEvent(MenuEvent be)
{
if (be.getEventType()==Events.OnClick)
MessageBox.prompt("test","The event fired!");

}
});

B:
menuItem1.addSelectionListener(new SelectionListener<MenuEvent>(){

public void componentSelected(MenuEvent ce)
{
// TODO Auto-generated method stub
MessageBox.prompt("test","The event fired!");
}
//@Override
public void handleEvent(MenuEvent ce)
{
// TODO Auto-generated method stub
MessageBox.prompt("test","The event fired!");
}

});
===========================
why B works well, but A is not ?

cqiao
26 Jun 2008, 4:53 AM
The C is correct one:
C:
menuItem1.addSelectionListener(new SelectionListener<MenuEvent>(){

public void componentSelected(MenuEvent ce)
{
//MessageBox.prompt("test","The event fired!");
}

public void handleEvent(MenuEvent ce)
{
//if (ce.getEventType()==Events.OnClick)
MessageBox.prompt("test","The event fired!"+ce.getEventType());
}

});
Why ce.getEventType()=-1?

zaccret
26 Jun 2008, 10:40 PM
What are you trying to do ? This should be enough :

menuItem1.addSelectionListener(new SelectionListener<MenuEvent>(){
public void componentSelected(MenuEvent ce)
{
// TODO Auto-generated method stub
MessageBox.prompt("test","The event fired!");
}
});ce.getEventType() returns you the GWT Event type. Look at the Event class. -1 is UNDEFINED. Don't know why you get that.

cqiao
27 Jun 2008, 3:55 AM
Thank you, zaccret!
I get ce.getEventType(), only want to watch if its value is EVENTS.OnClick.