javafx 2 - anucourses.cecs.anu.edu.au/courses/comp6710/lectures/x02.pdf · javafx and event...
TRANSCRIPT
![Page 1: JavaFX 2 - ANUcourses.cecs.anu.edu.au/courses/COMP6710/lectures/X02.pdf · JavaFX and Event Handling Event Handling Event handling is another control flow construct. • Branches](https://reader030.vdocuments.us/reader030/viewer/2022021710/5c09579f09d3f272358b6aaf/html5/thumbnails/1.jpg)
Introduction to Software Systems 1110/1140/1510/6710
JavaFX and Event Handling
JavaFX 2 X2
![Page 2: JavaFX 2 - ANUcourses.cecs.anu.edu.au/courses/COMP6710/lectures/X02.pdf · JavaFX and Event Handling Event Handling Event handling is another control flow construct. • Branches](https://reader030.vdocuments.us/reader030/viewer/2022021710/5c09579f09d3f272358b6aaf/html5/thumbnails/2.jpg)
Introduction to Software Systems 1110/1140/1510/6710
JavaFX and Event Handling
Java FX Scene Graph Tree of nodes, with a single ‘branch’ at the root • branch (may have children, eg Group, Region) • leaf (may not have children, eg Rectangle, Circle)
10
Copyright Oracle (http://docs.oracle.com/javafx/2/scenegraph/jfxpub-scenegraph.htm)
X2
![Page 3: JavaFX 2 - ANUcourses.cecs.anu.edu.au/courses/COMP6710/lectures/X02.pdf · JavaFX and Event Handling Event Handling Event handling is another control flow construct. • Branches](https://reader030.vdocuments.us/reader030/viewer/2022021710/5c09579f09d3f272358b6aaf/html5/thumbnails/3.jpg)
Introduction to Software Systems 1110/1140/1510/6710
JavaFX and Event Handling
Event Handling Event handling is another control flow construct. • Branches (a conditional or switch selects control flow)
• Loops (a loop repeats control flow)
• Methods (a method call nests control flow)
• Events (the occurrence of event changes control flow) – Event handling in UIs – Exception handling (later)
11 375-388
X2
![Page 4: JavaFX 2 - ANUcourses.cecs.anu.edu.au/courses/COMP6710/lectures/X02.pdf · JavaFX and Event Handling Event Handling Event handling is another control flow construct. • Branches](https://reader030.vdocuments.us/reader030/viewer/2022021710/5c09579f09d3f272358b6aaf/html5/thumbnails/4.jpg)
Introduction to Software Systems 1110/1140/1510/6710
JavaFX and Event Handling
Events and Passing Code in Java
An event handler will execute code you specify executed when a certain event occurs.
Q: How do I pass code as an argument in Java? A: Lambda expressions (since Java 8), see unit J09
12 375-388
X2
![Page 5: JavaFX 2 - ANUcourses.cecs.anu.edu.au/courses/COMP6710/lectures/X02.pdf · JavaFX and Event Handling Event Handling Event handling is another control flow construct. • Branches](https://reader030.vdocuments.us/reader030/viewer/2022021710/5c09579f09d3f272358b6aaf/html5/thumbnails/5.jpg)
Introduction to Software Systems 1110/1140/1510/6710
JavaFX and Event Handling
Events in JavaFX Events are instances of javafx.event.Event• Event properties:
– Event type – Source – Target
• Event handlers – Pass the Lambda expression. For example: scene.setOnKeyTyped(event -> { ...your code... })
13
X2