One of the conceptual shifts that must take place for you to do effective object-oriented programming is develop an understanding of how processing proceeds through a Java program versus how it proceeds through a program written in an iterative language, such as Pascal, C, or Basic.In a conventional language, processing begins at the "top" and proceeds linearly through the code, except as the flow of control is interrupted by loops, conditional statements, and function calls. In an object-oriented language, control can be visualized as passing from one object to another through messages. The whole process begins with some default method which, in turn, operates largely by sending messages to other objects, which send messages to other objects , . . . . Thus, the process is a like pinball machine in which balls/messages are bounced from one object to another.
This flow of control can be interrupted by users, such as pressing a button icon, selecting a menu item, or typing in a string to a textfield. When this happens, Java generates an Event. Events interrupt the normal flow of messages and are handled by special a special class, called
handleEvents
. Within that class, the program can checked for particular events, such as the pressing of a particular button, and take the appropriate action, usually by sending a message to a corresponding method.Two tutorials on events are provided. In this first one, the focus is on the basic concept and rudimentary processing. In the second, the discussion will be extended to cover events from the most common user interface components.
Topics
Begin discussion of basic Java Events.
- Event model
- Event class
- handleEvent method
- Event propagation
References
Useful references include:
- Introduction to O-O Programming in Java class tutorial
- Java Overview
- Sun's Java Development Kit (JDK)
- The API
- The API Class Hierarchy
- Source Code for JDK Packages
Assignment for Next Class