PDA

View Full Version : Somethings wrong with a custom event



treblereel
2 Nov 2011, 3:59 AM
Hi all, plz help me to find out whats wrong with my custome event SimpleEvents.AlertEvent, coz nothing happens

Here is a test EntryPoint:




public class EventsTest implements EntryPoint {
private SimpleWindow simpleWindow3;
private SimpleWindow simpleWindow2;
private Button btn;
private Observable Observable;


public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();


SimpleWindow simpleWindow = new SimpleWindow();

btn = new Button("Process");
btn.addListener(Events.Select,new Listener<ButtonEvent>() {
@Override public void handleEvent(ButtonEvent be) {


// Here i am trying to fire event SimpleEvents.AlertEvent

EventBus.getInstance().fireEvent(SimpleEvents.AlertEvent);

}
});



simpleWindow.addButton(btn);

rootPanel.add(simpleWindow);


simpleWindow2 = new SimpleWindow("First");

// i have add listener SimpleEvents.AlertEvent to catch Event from above

simpleWindow2.addListener(SimpleEvents.AlertEvent,new Listener<BaseEvent>(){
@Override public void handleEvent(BaseEvent be) {
System.out.println("Event First");
simpleWindow2.setHeading("changed ");
}

});

rootPanel.add(simpleWindow2);

}

}




EventBus:




public class EventBus extends BaseObservable{
private static EventBus instance;


protected EventBus(){
super();

}


public static EventBus getInstance(){
instance = (instance == null ? (instance = new EventBus()) :
instance);
return instance;

}

}



SimpleEvents:



public class SimpleEvents {

public static final EventType AlertEvent = new EventType();

}



Thanks for any help

sven
2 Nov 2011, 10:02 AM
What is SimpleWindow? Is simpleevent listening to the EventBus? Because else you add the listener to the wrong Observable.