JavaBean Events   «Prev  Next»
Lesson 2Event types
Objective Learn about low-level and semantic events.

Event types (low-level | Semantic)

Communicating with Events - JavaBeans

Events are a very important part of JavaBeans because they form the underlying mechanism by which Beans communicate. How can a Bean communicate using an event? Well, when an event occurs in a Bean the Bean sends an event notification to any application, applet, or other Bean interested in knowing about the event. So, if you click the mouse on a button Bean that is part of an e-mail application, for example, the Bean sends an event notification to the application. The application then processes the event and takes some kind of action, such as sending an e-mail message. In this example, the communication between the Bean and its parent application is carried out by the event. This type of scenario can exist between Beans and stand-alone applications, between Beans and applets, and even between two Beans. It is not hard to see that without events, and therefore without a means of communication, Beans would not be of much use.

Events form a fundamental part of the JavaBeans architecture in that they provide the means by which Beans communicate with applications and other Beans. JavaBeans inherits its event handling facility directly from the Java 1.1 delegation event model. JavaBeans, therefore, supports two different types of events: low-level events and semantic events[1]. Low-level events are events fired in response to a low-level input or visual user interface interaction. Examples of low-level events are mouse drags and key presses.


Low-level Events and JavaBeans

Low-level events
Following are the low-level events supported in the Java 1.1 API:
Low-level Event Description
ComponentEvent Fired when a Bean is resized, moved, hidden or shown.
FocusEvent Fired when a Bean receives or loses focus.
InputEvent Never actually fired; it serves as an organizational class for input (keyboard and mouse) events.
KeyEvent Fired when a Bean receives a key press or key release.
MouseEvent Fired when a Bean receives a mouse button click, mouse button release, mouse move, or mouse drag.

Low-level event

An event fired in response to a low-level input or visual user interface interaction.
Semantic events are events fired when an action occurs that is based on the semantics of a particular Bean. An example of a semantic event is a button press event, which is related to the specific function (semantics) of a button Bean. In the next lesson, you learn how event listeners are used to facilitate event communication.

Javabeans Semantic Events

Following are the semantic events supported in the Java 1.1 API

Semantic Events Description
ActionEventFired when a generic action occurs.
AdjustmentEventFired when a value is adjusted.
ItemEventFired when an item state changes.

[1]Semantic event: An event fired when an action occurs that is based on the semantics of a particular Bean.