Skip to content

A simple library implementing an event emitter in Java

License

Notifications You must be signed in to change notification settings

nicolas-van/eventemitter

Repository files navigation

Maven Central Gradle Build

eventemitter

A simple library implementing an event emitter in Java, made to use closures. It's way simpler and shorter than Swing's crappy EventListener.

Installation

See the page on search.maven.org for Gradle of Maven configuration per version.

Usage

// ExampleClass.java
package example;

import eventemitter.EventEmitter;
import lombok.Getter;
import lombok.NonNull;

public class ExampleClass {
    
    @Getter
    private final EventEmitter<String> statusChanged = new EventEmitter<>();
    
    @Getter
    @NonNull
    private String status = "";
    
    public void setStatus(String stat) {
        this.status = stat;
        this.getStatusChanged().trigger(stat);
    }
}
// ExampleConsumer.java
package example;

public class ExampleConsumer {
    public static void main(String[] args) {
        ExampleClass e = new ExampleClass();
        
        e.getStatusChanged().addConsumer((s) -> {
            System.out.println("New status is " + s);
        });
        
        e.setStatus("waiting");
    }
}

Javadoc

Link to the javadoc.

License

See the license file.

About

A simple library implementing an event emitter in Java

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages