SlideShare ist ein Scribd-Unternehmen logo
1 von 47
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic FunctionsWebStackAcademy
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernateelliando dias
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React NativeAmazon Web Services
 
Abstraction
AbstractionAbstraction
Abstractionadil raja
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Intro to React
Intro to ReactIntro to React
Intro to ReactJustin Reock
 
Php Presentation
Php PresentationPhp Presentation
Php PresentationManish Bothra
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Conceptsthinkphp
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENTjosemachoco
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript ProgrammingSehwan Noh
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - ObjectsWebStackAcademy
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Editionmoxuji
 

Was ist angesagt? (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
JavaScript - Chapter 6 - Basic Functions
 JavaScript - Chapter 6 - Basic Functions JavaScript - Chapter 6 - Basic Functions
JavaScript - Chapter 6 - Basic Functions
 
Json
JsonJson
Json
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Introduction to React Native
Introduction to React NativeIntroduction to React Native
Introduction to React Native
 
Abstraction
AbstractionAbstraction
Abstraction
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Php Presentation
Php PresentationPhp Presentation
Php Presentation
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
PHP slides
PHP slidesPHP slides
PHP slides
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
JAVA ENVIRONMENT
JAVA  ENVIRONMENTJAVA  ENVIRONMENT
JAVA ENVIRONMENT
 
JavaScript Programming
JavaScript ProgrammingJavaScript Programming
JavaScript Programming
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Edition
 
JavaFX Overview
JavaFX OverviewJavaFX Overview
JavaFX Overview
 

Ähnlich wie 004 - JavaFX Tutorial - Event Handling

Event driven architecture
Event driven architectureEvent driven architecture
Event driven architectureVinod Wilson
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptxusvirat1805
 
Module 5.pptx
Module 5.pptxModule 5.pptx
Module 5.pptxVeenaNaik23
 
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 IISivaSankari36
 
Events1
Events1Events1
Events1Nuha Noor
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationKnoldus Inc.
 
Testing Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationTesting Event Driven Architecture Presentation
Testing Event Driven Architecture PresentationKnoldus Inc.
 
Module3.11.pptx
Module3.11.pptxModule3.11.pptx
Module3.11.pptxVeenaNaik23
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handlingteach4uin
 
Event handling62
Event handling62Event handling62
Event handling62myrajendra
 
B2. activity and intent
B2. activity and intentB2. activity and intent
B2. activity and intentPERKYTORIALS
 
20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anney20141107 node js_eventemitterpattern_anney
20141107 node js_eventemitterpattern_anneyLearningTech
 
Chap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxChap - 2 - Event Handling.pptx
Chap - 2 - Event Handling.pptxTadeseBeyene
 
OOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxOOP Lecture 11-EventHandling1.pptx
OOP Lecture 11-EventHandling1.pptxTanzila Kehkashan
 

Ähnlich wie 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
 

Mehr von Mohammad Hossein Rimaz

Mehr von 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
 

KĂźrzlich hochgeladen

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfWilly Marroquin (WillyDevNET)
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto GonzĂĄlez Trastoy
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 

KĂźrzlich hochgeladen (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 

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