SlideShare a Scribd company logo
Brought to you by
Graphical User Interface in Java
Using JavaFX
Event Handling
1K. N. Toosi University of Technology
What is Event?
• 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.
• Every JavaFX event has:
• eventType
• source
• target
• JavaFX provides several events, including DragEvent, KeyEvent, MouseEvent,
ScrollEvent, and others. You can define your own event by extending the Event
class.
• Subclasses can define type specific properties:
• MouseEvent: x,y
• KeyEvent: code, character
2K. N. Toosi University of Technology
Event Properties:
3K. N. Toosi University of Technology
Property Description
Event Type Type of event that occurred.
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.
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 Hierarchy:
4K. N. Toosi University of Technology
EventObject
Event
InputEvent
KeyEvent MouseEvent DragEvent TouchEvent SwipeEvent …
ActionEvent WindowEvent
https://docs.oracle.com/javafx/2/events/processing.htm
Event Type Hierarchy:
5K. N. Toosi University of Technology
Event.ANY
InputEvent.ANY
KeyEvent.ANY
KeyEvent.KEY_PRESSED
KeyEvent.KEY_RELEASED
KeyEvent.KEY_TYPED
MouseEvent.ANY MouseEvent.MOUSE_PRESSED
MouseEvent.MOUSE_RELEASED
ActionEvent.ACTION
WindowEvent.ANY
WindowEvent.WINDOW_SHOWING
WindowEvent.WINDOW_SHOWN
https://docs.oracle.com/javafx/2/events/processing.htm
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
6K. N. Toosi University of Technology
Demo 1:
7K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
8K. N. Toosi University of Technology
Demo 1: Click on Green Circle
9K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 1: Circle Select as the target as the
first phase of Event Delivery Process.
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
10K. N. Toosi University of Technology
Demo 1: Click on Green Circle
11K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 2: Route construction happens in the
second phase from the scene graph.
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
12K. N. Toosi University of Technology
Demo 1: Click on Green Circle
13K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 3: In the event capturing phase, the
created event traverse from the top of the
scene graph to the target node.
• EventHandlers will not invoke
Event
Demo 1: Click on Green Circle
14K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 3: In the event capturing phase, the
created event traverse from the top of the
scene graph to the target node.
• EventHandlers will not invoke
Event
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
15K. N. Toosi University of Technology
Demo 1: Click on Green Circle
16K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 4: In the Event Bubbling phase, the
Event traverse from the bottom of the
scene graph to the root.
• EventHandlers will invoke in this phase
Event
Demo 1: Click on Green Circle
17K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 4: In the Event Bubbling phase, the
Event traverse from the bottom of the
scene graph to the root.
• EventHandlers will invoke in this phaseEvent
Event Delivery Process:
• Event Target Selection
• Depends on the particular event type
• Event Route Construction
• Specified by the event target
• Event Capturing Phase
• Event travels from the stage to the event target
• Event Bubbling Phase
• Events travels back from the target to the stage
18K. N. Toosi University of Technology
Event Handling
• Three methods of event handling
• Convenience methods
• setOnKeyPressed(eventHandler);
• setOn …
• Event handler / filter registration methods
• addEventHandler(eventType, eventHandler);
• addEventFilter(eventType,eventFilter);
• Event dispatcher property
• Differ in Complexity and level of control
19K. N. Toosi University of Technology
Event Handlers
• An event handler is executed during the event bubbling phase.
• If an event handler for a child node does not consume the event, an
event handler for a parent node can act on the event after a child
node processes it and can provide common event processing for
multiple child nodes.
• Handlers that are registered for the type of event that occurred are
executed as the event returns through the node that registered the
handler.
20K. N. Toosi University of Technology
Demo 1: Click on Green Circle
21K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 4: In the Event Bubbling phase, the
Event traverse from the bottom of the
scene graph to the root.
• EventHandlers will invoke in this phase
Event
Event Filters
• An event filter is executed during the event capturing phase.
• An event filter for a parent node can provide common event
processing for multiple child nodes and if desired, consume the event
to prevent the child node from receiving the event.
• Filters that are registered for the type of event that occurred are
executed as the event passes through the node that registered the
filter.
22K. N. Toosi University of Technology
Demo 1: Click on Green Circle
23K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Phase 3: In the event capturing phase, the
created event traverse from the top of the
scene graph to the target node.
• EventHandlers will not invoke
Event
Consuming of an Event
• An event can be consumed by an event filter or an event handler at any
point in the event dispatch chain by calling the consume() method.
• This method signals that processing of the event is complete and traversal
of the event dispatch chain ends.
• Consuming the event in an event filter prevents any child node on the
event dispatch chain from acting on the event.
• Consuming the event in an event handler stops any further processing of
the event by parent handlers on the event dispatch chain.
• If the node that consumes the event has more than one filter or handler
registered for the event, the peer filters or handlers are still executed.
24K. N. Toosi University of Technology
Event Handling
Convenience methods
• on<EventType>
• onMousePressed, onKeyTyped, onAction
• Easy way to install, remove or replace an event handler
• Sufficient for most use cases
• Only one handler per event type
• For selected event types only
• No support for event filter registration
25K. N. Toosi University of Technology
Event Handling
Convenience methods
26K. N. Toosi University of Technology
Event Handling
Handler / Filter registration methods
• Allow to register multiple event handlers / filters for a signle event
type
• addEventHandler, addEventFilter methods
• Can Register one event handler / filter for a whole class of events
• All mouse events, all input events, all events
• Specific handlers / filters executed before the generic ones
• If you wrote two handler for two type of event which they are KeyEvent.KEY_TYPED and
InputEvent.ANY the more specified one which is KeyEvent will be called before the
handler of the generic one which is InputEvent
• Execution order of event handlers at the same level is unspecified and
not guaranteed
• Exception: on<EventType> handlers executed last
27K. N. Toosi University of Technology
Event Handling
Handler / Filter registration methods
28K. N. Toosi University of Technology
Handler or Filter?
• Different execution order
• Event handler for leaf nodes
• Event handler installed on a branch node
• Allows to define a default event response for all child nodes
• A child node can still define a more specific event response
• Event filter installed on a branch node
• Can override / force an event response
• Can block events from reaching their destination
29K. N. Toosi University of Technology
Demo 1:
30K. N. Toosi University of Technology
Demo 1:
31K. N. Toosi University of Technology
Demo 1:
32K. N. Toosi University of Technology
Demo 1:
33K. N. Toosi University of Technology
Demo 1:
34K. N. Toosi University of Technology
Demo 1:
35K. N. Toosi University of Technology
Demo 1: Click on Green Circle
36K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : Stage
• Event Target : Circle
• Executed : Stage Filter
Event
Demo 1: Click on Green Circle
37K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : Scene
• Event Target : Circle
• Executed : NothingEvent
Demo 1: Click on Green Circle
38K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : VBox
• Event Target : Circle
• Executed : VBox Filter
Event
Demo 1: Click on Green Circle
39K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : HBox
• Event Target : Circle
• Executed : HBox Filter
Event
Demo 1: Click on Green Circle
40K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : Circle
• Event Target : Circle
• Executed : Circle Filter
Event
Demo 1: Click on Green Circle
41K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : Circle
• Event Target : Circle
• Executed : Circle Handler
Event
Demo 1: Click on Green Circle
42K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : HBox
• Event Target : Circle
• Executed : HBox Handler
Event
Demo 1: Click on Green Circle
43K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : VBox
• Event Target : Circle
• Executed : VBox Handler
if not Consumed
Event
Demo 1: Click on Green Circle
44K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : VBox
• Event Target : Scene
• Executed : Nothing
if not Consumed
Event
Demo 1: Click on Green Circle
45K. N. Toosi University of Technology
Stage
Scene
VBox
Rectangle HBox
Circle Polygon
• Event Source : Stage
• Event Target : Circle
• Executed : Stage Handler
if not Consumed
Event
Resources & Refrences
• Oracle’s JavaFX: Handling Events Tutorial;
https://docs.oracle.com/javase/8/javafx/events-tutorial/events.htm
• JavaFX Event System Walk-through, Presented by eva krejčířová on
Oracle JavaOne 2012 conf;
https://www.youtube.com/watch?v=PNLNEzXcZE4
• Codes:
https://gist.github.com/mhrimaz/009afb0ffe444f478ceec5063dbbf277
46K. N. Toosi University of Technology
Brought to you by
Happy Coding 
47K. N. Toosi University of Technology

More Related Content

What's hot

Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
Manisha Keim
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
Basant Medhat
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
Md. Aftab Uddin Kajal
 
Class Diagram
Class DiagramClass Diagram
Class Diagram
Rana_brothers
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture
AqsaHayat3
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
thinkphp
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
DrSonali Vyas
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
Shreyans Pathak
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
Madhuri Kavade
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
Faisal Aziz
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
FalgunSorathiya
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
Vishwa Mohan
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
Information Technology
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
Lovely Professional University
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
Hemant Chetwani
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
Prem Sanil
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
Arun Prasad
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
BG Java EE Course
 

What's hot (20)

Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
LINQ in C#
LINQ in C#LINQ in C#
LINQ in C#
 
ASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code firstASP.NET Core MVC with EF Core code first
ASP.NET Core MVC with EF Core code first
 
Class Diagram
Class DiagramClass Diagram
Class Diagram
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Visual programming lecture
Visual programming lecture Visual programming lecture
Visual programming lecture
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
ADO .Net
ADO .Net ADO .Net
ADO .Net
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Web forms in ASP.net
Web forms in ASP.netWeb forms in ASP.net
Web forms in ASP.net
 
Vb.net ide
Vb.net ideVb.net ide
Vb.net ide
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
CSharp Presentation
CSharp PresentationCSharp Presentation
CSharp Presentation
 
JDBC – Java Database Connectivity
JDBC – Java Database ConnectivityJDBC – Java Database Connectivity
JDBC – Java Database Connectivity
 
Abstract class in java
Abstract class in javaAbstract class in java
Abstract class in java
 
Properties and indexers in C#
Properties and indexers in C#Properties and indexers in C#
Properties and indexers in C#
 
MVC Architecture
MVC ArchitectureMVC Architecture
MVC Architecture
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 

Similar to 004 - JavaFX Tutorial - Event Handling

Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
Vinod Wilson
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
Jyothishmathi Institute of Technology and Science Karimnagar
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptx
VeenaNaik23
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
SivaSankari36
 
Events1
Events1Events1
Events1
Nuha Noor
 
Event bus for android
Event bus for androidEvent bus for android
Event bus for android
丞廷 鄭
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
Knoldus Inc.
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
Knoldus Inc.
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
VeenaNaik23
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
teach4uin
 
Event handling62
Event handling62Event handling62
Event handling62
myrajendra
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
PERKYTORIALS
 
20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anney20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anney
LearningTech
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
TadeseBeyene
 
Event handling
Event handlingEvent handling
Event handling
Ravi_Kant_Sahu
 
Event handling
Event handlingEvent handling
Event handling
Ravi Kant Sahu
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
Tanzila Kehkashan
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
VamsiKrishna424209
 
42c
42c42c

Similar to 004 - JavaFX Tutorial - Event Handling (20)

Event driven architecture
Event driven architectureEvent driven architecture
Event driven architecture
 
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptx
 
PROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part IIPROGRAMMING IN JAVA- unit 4-part II
PROGRAMMING IN JAVA- unit 4-part II
 
Events1
Events1Events1
Events1
 
Event bus for android
Event bus for androidEvent bus for android
Event bus for android
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture Presentation
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptx
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
Event handling62
Event handling62Event handling62
Event handling62
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intent
 
20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anney20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anney
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptx
 
Event handling
Event handlingEvent handling
Event handling
 
Event handling
Event handlingEvent handling
Event handling
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptx
 
EventHandling.pptx
EventHandling.pptxEventHandling.pptx
EventHandling.pptx
 
42c
42c42c
42c
 

More from Mohammad Hossein Rimaz

003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
Mohammad Hossein Rimaz
 
002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started
Mohammad Hossein Rimaz
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
Mohammad Hossein Rimaz
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
Mohammad Hossein Rimaz
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
Mohammad Hossein Rimaz
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
Mohammad Hossein Rimaz
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
Mohammad Hossein Rimaz
 

More from Mohammad Hossein Rimaz (7)

003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts003 - JavaFX Tutorial - Layouts
003 - JavaFX Tutorial - Layouts
 
002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started002- JavaFX Tutorial - Getting Started
002- JavaFX Tutorial - Getting Started
 
Java 9, JShell, and Modularity
Java 9, JShell, and ModularityJava 9, JShell, and Modularity
Java 9, JShell, and Modularity
 
Quick introduction to scala
Quick introduction to scalaQuick introduction to scala
Quick introduction to scala
 
Continuous integration with Jenkins
Continuous integration with JenkinsContinuous integration with Jenkins
Continuous integration with Jenkins
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 

Recently uploaded

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
Hironori Washizaki
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
pavan998932
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
Gerardo Pardo-Castellote
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
Shane Coughlan
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
lorraineandreiamcidl
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 

Recently uploaded (20)

Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024SWEBOK and Education at FUSE Okinawa 2024
SWEBOK and Education at FUSE Okinawa 2024
 
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
What is Augmented Reality Image Tracking
What is Augmented Reality Image TrackingWhat is Augmented Reality Image Tracking
What is Augmented Reality Image Tracking
 
DDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systemsDDS-Security 1.2 - What's New? Stronger security for long-running systems
DDS-Security 1.2 - What's New? Stronger security for long-running systems
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
openEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain SecurityopenEuler Case Study - The Journey to Supply Chain Security
openEuler Case Study - The Journey to Supply Chain Security
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptxLORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
LORRAINE ANDREI_LEQUIGAN_HOW TO USE WHATSAPP.pptx
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 

004 - JavaFX Tutorial - Event Handling

  • 1. Brought to you by Graphical User Interface in Java Using JavaFX Event Handling 1K. N. Toosi University of Technology
  • 2. What is Event? • 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. • Every JavaFX event has: • eventType • source • target • JavaFX provides several events, including DragEvent, KeyEvent, MouseEvent, ScrollEvent, and others. You can define your own event by extending the Event class. • Subclasses can define type specific properties: • MouseEvent: x,y • KeyEvent: code, character 2K. N. Toosi University of Technology
  • 3. Event Properties: 3K. N. Toosi University of Technology Property Description Event Type Type of event that occurred. 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. 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.
  • 4. Event Hierarchy: 4K. N. Toosi University of Technology EventObject Event InputEvent KeyEvent MouseEvent DragEvent TouchEvent SwipeEvent … ActionEvent WindowEvent https://docs.oracle.com/javafx/2/events/processing.htm
  • 5. Event Type Hierarchy: 5K. N. Toosi University of Technology Event.ANY InputEvent.ANY KeyEvent.ANY KeyEvent.KEY_PRESSED KeyEvent.KEY_RELEASED KeyEvent.KEY_TYPED MouseEvent.ANY MouseEvent.MOUSE_PRESSED MouseEvent.MOUSE_RELEASED ActionEvent.ACTION WindowEvent.ANY WindowEvent.WINDOW_SHOWING WindowEvent.WINDOW_SHOWN https://docs.oracle.com/javafx/2/events/processing.htm
  • 6. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 6K. N. Toosi University of Technology
  • 7. Demo 1: 7K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon
  • 8. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 8K. N. Toosi University of Technology
  • 9. Demo 1: Click on Green Circle 9K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 1: Circle Select as the target as the first phase of Event Delivery Process.
  • 10. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 10K. N. Toosi University of Technology
  • 11. Demo 1: Click on Green Circle 11K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 2: Route construction happens in the second phase from the scene graph.
  • 12. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 12K. N. Toosi University of Technology
  • 13. Demo 1: Click on Green Circle 13K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 3: In the event capturing phase, the created event traverse from the top of the scene graph to the target node. • EventHandlers will not invoke Event
  • 14. Demo 1: Click on Green Circle 14K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 3: In the event capturing phase, the created event traverse from the top of the scene graph to the target node. • EventHandlers will not invoke Event
  • 15. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 15K. N. Toosi University of Technology
  • 16. Demo 1: Click on Green Circle 16K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 4: In the Event Bubbling phase, the Event traverse from the bottom of the scene graph to the root. • EventHandlers will invoke in this phase Event
  • 17. Demo 1: Click on Green Circle 17K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 4: In the Event Bubbling phase, the Event traverse from the bottom of the scene graph to the root. • EventHandlers will invoke in this phaseEvent
  • 18. Event Delivery Process: • Event Target Selection • Depends on the particular event type • Event Route Construction • Specified by the event target • Event Capturing Phase • Event travels from the stage to the event target • Event Bubbling Phase • Events travels back from the target to the stage 18K. N. Toosi University of Technology
  • 19. Event Handling • Three methods of event handling • Convenience methods • setOnKeyPressed(eventHandler); • setOn … • Event handler / filter registration methods • addEventHandler(eventType, eventHandler); • addEventFilter(eventType,eventFilter); • Event dispatcher property • Differ in Complexity and level of control 19K. N. Toosi University of Technology
  • 20. Event Handlers • An event handler is executed during the event bubbling phase. • If an event handler for a child node does not consume the event, an event handler for a parent node can act on the event after a child node processes it and can provide common event processing for multiple child nodes. • Handlers that are registered for the type of event that occurred are executed as the event returns through the node that registered the handler. 20K. N. Toosi University of Technology
  • 21. Demo 1: Click on Green Circle 21K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 4: In the Event Bubbling phase, the Event traverse from the bottom of the scene graph to the root. • EventHandlers will invoke in this phase Event
  • 22. Event Filters • An event filter is executed during the event capturing phase. • An event filter for a parent node can provide common event processing for multiple child nodes and if desired, consume the event to prevent the child node from receiving the event. • Filters that are registered for the type of event that occurred are executed as the event passes through the node that registered the filter. 22K. N. Toosi University of Technology
  • 23. Demo 1: Click on Green Circle 23K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Phase 3: In the event capturing phase, the created event traverse from the top of the scene graph to the target node. • EventHandlers will not invoke Event
  • 24. Consuming of an Event • An event can be consumed by an event filter or an event handler at any point in the event dispatch chain by calling the consume() method. • This method signals that processing of the event is complete and traversal of the event dispatch chain ends. • Consuming the event in an event filter prevents any child node on the event dispatch chain from acting on the event. • Consuming the event in an event handler stops any further processing of the event by parent handlers on the event dispatch chain. • If the node that consumes the event has more than one filter or handler registered for the event, the peer filters or handlers are still executed. 24K. N. Toosi University of Technology
  • 25. Event Handling Convenience methods • on<EventType> • onMousePressed, onKeyTyped, onAction • Easy way to install, remove or replace an event handler • Sufficient for most use cases • Only one handler per event type • For selected event types only • No support for event filter registration 25K. N. Toosi University of Technology
  • 26. Event Handling Convenience methods 26K. N. Toosi University of Technology
  • 27. Event Handling Handler / Filter registration methods • Allow to register multiple event handlers / filters for a signle event type • addEventHandler, addEventFilter methods • Can Register one event handler / filter for a whole class of events • All mouse events, all input events, all events • Specific handlers / filters executed before the generic ones • If you wrote two handler for two type of event which they are KeyEvent.KEY_TYPED and InputEvent.ANY the more specified one which is KeyEvent will be called before the handler of the generic one which is InputEvent • Execution order of event handlers at the same level is unspecified and not guaranteed • Exception: on<EventType> handlers executed last 27K. N. Toosi University of Technology
  • 28. Event Handling Handler / Filter registration methods 28K. N. Toosi University of Technology
  • 29. Handler or Filter? • Different execution order • Event handler for leaf nodes • Event handler installed on a branch node • Allows to define a default event response for all child nodes • A child node can still define a more specific event response • Event filter installed on a branch node • Can override / force an event response • Can block events from reaching their destination 29K. N. Toosi University of Technology
  • 30. Demo 1: 30K. N. Toosi University of Technology
  • 31. Demo 1: 31K. N. Toosi University of Technology
  • 32. Demo 1: 32K. N. Toosi University of Technology
  • 33. Demo 1: 33K. N. Toosi University of Technology
  • 34. Demo 1: 34K. N. Toosi University of Technology
  • 35. Demo 1: 35K. N. Toosi University of Technology
  • 36. Demo 1: Click on Green Circle 36K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : Stage • Event Target : Circle • Executed : Stage Filter Event
  • 37. Demo 1: Click on Green Circle 37K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : Scene • Event Target : Circle • Executed : NothingEvent
  • 38. Demo 1: Click on Green Circle 38K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : VBox • Event Target : Circle • Executed : VBox Filter Event
  • 39. Demo 1: Click on Green Circle 39K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : HBox • Event Target : Circle • Executed : HBox Filter Event
  • 40. Demo 1: Click on Green Circle 40K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : Circle • Event Target : Circle • Executed : Circle Filter Event
  • 41. Demo 1: Click on Green Circle 41K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : Circle • Event Target : Circle • Executed : Circle Handler Event
  • 42. Demo 1: Click on Green Circle 42K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : HBox • Event Target : Circle • Executed : HBox Handler Event
  • 43. Demo 1: Click on Green Circle 43K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : VBox • Event Target : Circle • Executed : VBox Handler if not Consumed Event
  • 44. Demo 1: Click on Green Circle 44K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : VBox • Event Target : Scene • Executed : Nothing if not Consumed Event
  • 45. Demo 1: Click on Green Circle 45K. N. Toosi University of Technology Stage Scene VBox Rectangle HBox Circle Polygon • Event Source : Stage • Event Target : Circle • Executed : Stage Handler if not Consumed Event
  • 46. Resources & Refrences • Oracle’s JavaFX: Handling Events Tutorial; https://docs.oracle.com/javase/8/javafx/events-tutorial/events.htm • JavaFX Event System Walk-through, Presented by eva krejčířová on Oracle JavaOne 2012 conf; https://www.youtube.com/watch?v=PNLNEzXcZE4 • Codes: https://gist.github.com/mhrimaz/009afb0ffe444f478ceec5063dbbf277 46K. N. Toosi University of Technology
  • 47. Brought to you by Happy Coding  47K. N. Toosi University of Technology