-
Notifications
You must be signed in to change notification settings - Fork 0
Events
Pieter edited this page Jun 28, 2024
·
8 revisions
It's easy to create an event. Just create a class and implement the Event
interface.
- Create a new class.
- Implement the
Event
interface. - Done.
public class MyEvent implements Event {
private final String message;
public MyEvent(String message) {
this.message = message;
}
public String getMessage() {
return message;
}
}
You can also create an event using records. Just create a record and implement the Event
interface.
- Create a new record.
- Implement the
Event
interface. - Done.
public record MyRecordEvent(String message) implements Event {
}
To call an event, you use an instance of Sees
and use the call
method.
- Get the default instance of
Sees
(or create a new instance). - Call an event. (This method returns a
boolean
value that indicates if the event was canceled.) - Done.
public class Main {
public static void main(String[] args) {
// Get the default instance of `Sees`.
Sees sees = Sees.getInstance();
// Call an event.
boolean cancelled = sees.call(new MyEvent("Hello, World! from MyEvent"));
}
}