public abstract class EventSource<S> extends Object
GraphicsContext2D ctx = GraphicsContext2D.getOrCreate("canvas");
EventSource es = EventSource.create(ctx, "canvas");
es.addEventHandler(MouseEvent.MOUSE_PRESSED, new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent event) {
GraphicsContext2D g2d = (GraphicsContext2D) event.getSource();
g2d.setFillStyle(ctx.getWebColor("orange"));
g2d.fillCircle((float) event.getX(), (float) event.getY(), 10);
}
});
Then add your EventHandlers there and receive Events.Constructor and Description |
---|
EventSource() |
Modifier and Type | Method and Description |
---|---|
abstract <T extends Event> |
addEventHandler(Event.Type<T> type,
EventHandler<T> handler)
Add an EventHandler to this EventSource to receive Events of the
specified type.
|
static <S> EventSource |
create(S source,
String id)
Create a new EventSource for the HTML Element identified by the id and
pass an object, which will be used as the source in any Event.
|
static <S> EventSource |
create(S source,
String id,
boolean documentFiresKeyEvents)
Create a new EventSource for the HTML Element identified by the id and
pass an object, which will be used as the source in any Event.
|
abstract <T extends Event> |
removeEventHandler(Event.Type<T> type,
EventHandler<T> handler)
Remove the EventHandler
|
public abstract <T extends Event> void addEventHandler(Event.Type<T> type, EventHandler<T> handler)
T
- The event class this type applies to.type
- The Type of Event you're interested in, e.g.
MouseEvent.MOUSE_CLICKED.handler
- The EventHandler which should receive the event.public abstract <T extends Event> void removeEventHandler(Event.Type<T> type, EventHandler<T> handler)
T
- The event class this type applies to.type
- The Type of Event you want to remove it from listening to.handler
- The handler you want to remove.public static <S> EventSource create(S source, String id)
S
- The type of the source object that will be used when
dispatching events.source
- The object that will be the source in all events from this
EventSource.id
- The id of the HTML-Element you want to receive events from.public static <S> EventSource create(S source, String id, boolean documentFiresKeyEvents)
S
- The type of the source object that will be used when
dispatching events.source
- The object that will be the source in all events from this
EventSource.id
- The id of the HTML-Element you want to receive events from.documentFiresKeyEvents
- if true document fires keyevents instead of elementCopyright © 2019. All Rights Reserved.