Java Reference
In-Depth Information
K
EY
T
ERMS
anonymous inner class
594
functional interface
598
event 588
event-driven programming
lambda expression
597
588
inner class 591
key code 604
observable object 607
single abstract method interface
event handler 589
event-handler interface
589
event object 588
event source object
598
588
C
HAPTER
S
UMMARY
1.
The root class of the JavaFX event classes is
javafx.event.Event
, which is a sub-
class of
java.util.EventObject
. The subclasses of
Event
deal with special types
of events, such as action events, window events, mouse events, and key events. If a node
can fire an event, any subclass of the node can fire the same type of event.
2.
The handler object's class must implement the corresponding
event-handler interface
.
JavaFX provides a handler interface
EventHandler<T extends Event>
for every
event class
T
. The handler interface contains the
handle(T e)
method for handling
event
e
.
3.
The handler object must be registered by the
source object
. Registration methods
depend on the event type. For an action event, the method is
setOnAction
. For a
mouse-pressed event, the method is
setOnMousePressed
. For a key-pressed event,
the method is
setOnKeyPressed
.
4.
An
inner class
, or
nested class
, is defined within the scope of another class. An inner
class can reference the data and methods defined in the outer class in which it nests, so
you need not pass the reference of the outer class to the constructor of the inner class.
5.
An anonymous inner class can be used to shorten the code for event handling. Further-
more, a lambda expression can be used to greatly simplify the event-handling code for
functional interface handlers.
6.
A
functional interface
is an interface with exactly one abstract method. This is also
known as a single abstract method (SAM) interface.
7.
A
MouseEvent
is fired whenever a mouse button is pressed, released, clicked, moved,
or dragged on a node or a scene. The
getButton()
method can be used to detect which
mouse button is pressed for the event.
8.
A
KeyEvent
is fired whenever a key is pressed, released, or typed on a node or a scene.
The
getCode()
method can be used to return the code value for the key.
9.
An instance of
Observable
is known as an observable object, which contains the
addListener(InvalidationListener listener)
method for adding a listener.
Once the value is changed in the property, a listener is notified. The listener class should
implement the
InvalidationListener
interface, which uses the
invalidated
method to handle the property value change.
10.
The abstract
Animation
class provides the core functionalities for animations in
JavaFX.
PathTransition
,
FadeTransition
, and
Timeline
are specialized classes
for implementing animations.
Search WWH ::
Custom Search