Institute of Computer Science
  1. Courses
  2. 2019/20 spring
  3. Object-Oriented Programming (Narva College) (LTAT.NR.003)
ET
Log in

Object-Oriented Programming (Narva College) 2019/20 spring

  • Home
  • Materials
  • Grading
  • Java Glossary
  • Cheat sheet (S1-S6)
  • Source Example
  • Links
Chapter 8

Introduction

Last chapter's material focuses on the basics elements of JavaFX programs. Nevertheless, one important part is left out there - event handling. Most GUI controls generate events and channel the program flow.

An event can be defined as a signal to the program that something has happened. Events are triggered by external user actions, such as mouse movements, mouse clicks, and keystrokes. The program can be programmed to respond or ignore the triggered event.

In JavaFX, any event is an instance of class javafx.event.Event or any subclass of Event. Every event includes information about the event type, the event source and the event target. Therefore, the events can be divided into DragEvent, KeyEvent, TouchEvent etc.

Each event type can further be classified within its class. For example, the KeyEvent class contains the following event types: KEY_PRESSED, KEY_RELEASED, KEY_TYPED. In the subtypes, the event type ANY is used to mean any event type in the present event class. For example, to provide the same response to any type of a key event, use KeyEvent.ANY as the event type. To respond only when a key is released, use the KeyEvent.KEY_RELEASED event type.

A component that creates an event and fires it is called the event source object, or simply source object or source component. For example, a button is the source object for the buttonclicking action event. To respond to a button click, we need to write a piece of code that processes the button-clicking action. We need to create an object which is capable of handling the action event on a button. This object is called an event handler.

Used resources:

JavaFX tutorial "JavaFX: Handling Events".

Chapter 8
  • Institute of Computer Science
  • Faculty of Science and Technology
  • University of Tartu
In case of technical problems or questions write to:

Contact the course organizers with the organizational and course content questions.
The proprietary copyrights of educational materials belong to the University of Tartu. The use of educational materials is permitted for the purposes and under the conditions provided for in the copyright law for the free use of a work. When using educational materials, the user is obligated to give credit to the author of the educational materials.
The use of educational materials for other purposes is allowed only with the prior written consent of the University of Tartu.
Terms of use for the Courses environment