Registering events handlers

To catch an event, EventHandler must be registered in EventBus:

EventHandler handler = new EventHandler() {
    @Override
    public void onEvent(Event event) {

    }
};

eventBus.addHandler(SampleEvent.class, handler);

The other way to register a handler is by using annotations. Event consumer class must contain the method with a single parameter, and its type must be equal to expected event type.

SampleConsumer.java. 

public static class SampleConsumer {

	@HandleEvent
	public void onCatchSomeNiceEvent(SampleEvent event) {
	}

	@HandleEvent
	public void onEvent01(ImportantEvent event) {
	}
}

The instance of class must be registered in Eventbus:

eventBus.registerAll(consumer);

Once this is in place, EventBus will be added as the event handler for two different events.