Event Driven Programming
1 Abstract
Event Driven Programming. Fundamentals. JavaFX implementations.
2 Event Driven Prog
2.1 What is an event?
- Def is too complicated. Ex: a key-press, a key-release, mouse gesture, a file changing from read-only to write-also, CPU becoming 95% loaded, disk being 75% vacant, …
- An event is modeled as an instantaneous occurrence. A real event that has a duration is modeled as event-begin and even-end – ex: key board key-press and then key-release.
- The discovery of events is the responsibility of the "underlying" system.
2.2 Overview
- Event details: source, time stamp,
- Event Driven Prog is an important paradigm. Independent of PLs.
- A main loop over a table of (event –> action) pairs.
- Classifying events, and pairing them up with actions is the even driven paradigm.
- https://en.wikipedia.org/wiki/Event-driven_programming
2.3 Actions and Listeners
- Action is often collaborative among several event handlers listening to the event.
- The (event –> action) becomes (event e –> send-to-listeners(e))
2.4 Complications
- What is the time gap tg between an event happening, and the begin of an action?
- In this tg can more events happen?
- Can events happen concurrently?
- Can we listen to events happening in remote systems?
- Can actions be executed concurrently?
2.5 JavaFX
- Java8 + JavaFX actions are typically written as Lambda Expressions.
- ../Java8/JavaFX-EventDrivenProgramming-stonybrook.pdf
Event-Driven Programming in JavaFX, slides, SUNY Stonybrook 2015;
includes src code of examples
- Explains Anonymous Classes
- Explains Inner Classes
- Explains Lambda Expressions
- http://gluonhq.com/labs/javafxports/ JavaFX on Mobile (Android + iOS). Open Source.
2.6 Agents
- Meyers book, Chapter 18: PDF high-level intro to Event-driven design, slides, not JavaFX.
3 GoL
- Game-Of-Life, Redo updated to include event-driven
4 References
- https://www.cs.rit.edu/~csci242/Lectures/14/Event-diagrams.pdf Java GUIs in JavaFX. 2015. Recommended Reading.