Skip to content

ComFreek/GenericEventListeners

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

GenericEventListeners for Java

Usage

  1. Derive your class from Listenable
class MyClass extends Listenable {
}
  1. Use addActionListener() for registering for an event type and implement the Listener interface.
class Main {
      public static void main(String[] args) {
        MyClass myObj = new MyClass();
        myObj.addEventListener("dispatched", new Listener<String>() {
            public boolean run(Event<String> e) {
              System.out.println(e.data);
            }
        });
        myObj.doDispatch();
      }
}
  1. Dispatch an event from your Listenable class:
class MyClass extends Listenable {
      public void doDispatch() {
        dispatchEvent( new Event<String>("dispatched", "Hello World!") );
      }
}

Warning: dispatchEvent() does not check whether the type of the dispatched Event (here String) and the registered listeners match!

About

Author: @comfreek
License: MIT license, see LICENSE file for more information.

About

GenericEventListeners for Java.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages