Interface IEventListener
-
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface IEventListener
The interface can be implemented to handle a single event type or it can be used to capture multiple events. The example below shows how to create separate event handlers.class ConnectionHandler implements IEventListener { void dispatch(BaseEvent evt) throws SFSException { // connection event code goes here } } class LoginHandler implements IEventListener { void dispatch(BaseEvent evt) throws SFSException { // login event code goes here } } SmartFox sfs = new SmartFox(), sfs.addEventListener(SFSEvent.CONNECTION, new ConnectionHandler()); sfs.addEventListener(SFSEvent.LOGIN, new LoginHandler());
The following example demonstrates how to use a single implementation to deal with multiple events. class EventHandler implements IEventListener { void dispatch(BaseEvent evt) throws SFSException { if (evt.getType().equals(SFSEvent.CONNECTION)) { // connection event code goes here } else if (evt.getType().equals(SFSEvent.LOGIN)) { // login event code goes here } else if ... } } SmartFox sfs = new SmartFox(), sfs.addEventListener(SFSEvent.CONNECTION, new ConnectionHandler()); sfs.addEventListener(SFSEvent.LOGIN, new LoginHandler());
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
dispatch(BaseEvent evt)
The method is invoked when the Event is dispatched.
-
-
-
Method Detail
-
dispatch
void dispatch(BaseEvent evt) throws com.smartfoxserver.v2.exceptions.SFSException
The method is invoked when the Event is dispatched.
-
-