Servis-Rhino 4211B Betriebsanweisung Seite 283

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 298
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 282
JavaFX TilePane
JavaFX TitledPane
JavaFX VBox
JavaFX Other classes
JavaFX Popup
JavaFX PopupWindow
JavaFX Event Handling
Event handling is the notion that when a user interacts with JavaFX components, they can fire
events. These events can then be caught be event listeners and acted upon. For example, if we add
a button to our solution, then the click of the button is meant to drive some logic. This means that
we have to register the desired logic as a listener upon button click events.
The core to the story is the notion of the javafx.event.Event class. This class represents a
generic event and can be subclassed to create more specialized versions. Among the core properties
of an event are:
Event type – What kind of event does this event represent
Source – Who originated the event
Target – Who is the target of the event
When we wish to register an event handler (the code that catches the event), we can use the
addEventHandler() method. This takes two properties:
The type of the event we are watching for.
An instance of an EventHandler to be given control when the event is detected.
The type of event will be a subclass of EventType
A class which can receive events implements the EventTarget interface. This includes all the
existing atomic components.
Now, let us get practical. Let us assume we want to create a new event called "MyEvent". We
could build this as follows:
public static class MyEvent extends Event {
private static final long serialVersionUID = 1L;
public MyEvent(EventType<? extends MyEvent> eventType) {
super(eventType);
}
public static final EventType<MyEvent> ANY = new EventType<MyEvent>(Event.ANY, "MYEVENT");
public static final EventType<MyEvent> MYEVENT_A = new EventType<MyEvent>(MyEvent.ANY,
"MYEVENT_A");
}
Now if we wish to fire such an event, we can call:
fireEvent(new MyEvent(MyEvent.MYEVENT_A));
To catch this event, we can use:
myClass.addEventHandler(MyEvent.MYEVENT_A, new EventHandler<MyEvent>() {
Page 283
Seitenansicht 282
1 2 ... 278 279 280 281 282 283 284 285 286 287 288 ... 297 298

Kommentare zu diesen Handbüchern

Keine Kommentare