Rohini 58916976667
Rohini 58916976667
Using JavaFX, several types of applications such as desktop, web, and graphical
applications can be developed. Most of the applications in the current world need
user interaction to work. For that, the event concept is used from JavaFX. An
event is said to have happened in the situations where the user interacts with the
button press, page scrolling, etc. That is, these events are able to give a
1. MouseEvent: This event occurs in the situation where the mouse is clicked.
Syntax:
2. KeyEvent: This event occurs in the situation where a keystroke happens at the node.
Syntax:
3. DragEvent: This event occurs in the situation where dragging of the mouse is done.
Actions: Entering drag, dropping drag, entering target, exiting target, drag over.
Syntax:
4. WindowEvent: This event occurs in the situation where a keystroke happens at the
node.
Syntax:
EventHandler<WindowEvent> eh = new EventHandler<WindowEvent>()
has to have happened when an event occurs and how to control that
particular event.
For this, a code is used as an event handler that gets executed at the time
JavaFX offers several handlers as well as filters for handling the events.
That is, for every event in JavaFX, it has a target which is the node where
the event has occurred (these nodes can be scene, window, or node), a
source where the event has generated (mouse, keys, etc.), type of the
Events
An event represents an occurrence of something of interest to the application, such
as a mouse being moved or a key being pressed. In JavaFX, an event is an instance
of
the javafx.event.Event class or any subclass of Event. JavaFX provides several
events, including DragEvent, KeyEvent, MouseEvent, ScrollEvent, and others.
You can define yourown event by extending the Event class.
Property Description
Source Origin of the event, with respect to the location of the event in the event
dispatch chain. The source changes as the event is passed along the chain.
Property Description
Target Node on which the action occurred and the end node in the event dispatch
chain. The target does not change, however if an event filter consumes the
event during the event capturing phase, the target will not receive the event.
Event Types
An event type is an instance of the EventType class. Event types further classify
the events of a single event class. For example, the KeyEvent class contains the
following event types:
KEY_PRESSED
KEY_RELEASED
KEY_TYPED
Event types are hierarchical. Every event type has a name and a super type. For
example, the name of the event for a key being pressed is KEY_PRESSED, and the
super type
is KeyEvent.ANY. The super type of the top-level event type is null. Figure 1-
1 shows asubset of the hierarchy.
Event Targets
The target of an event can be an instance of any class that implements
the EventTarget interface. The implementation of the buildEventDispatchChain
creates theevent dispatch chain that the event must travel to reach the target.
The Window, Scene, and Node classes implement the EventTarget interface and
subclasses of those classes inherit the implementation. Therefore, most of the
elements in your user interface have their dispatch chain defined, enabling you to
focus on responding to the events and not be concerned with creating the event
dispatch chain.
If you create a custom UI control that responds to user actions and that control is a
subclass of Window, Scene, or Node, your control is an event target through
inheritance. If your control or an element of your control is not a subclass of
Window, Scene, or Node, you must implement the EventTarget interface for that
control or element. For example,
the MenuBar control is a target through inheritance, but the MenuItem element
of a menu bar must implement the EventTarget interface so that it can receive
events.