JavaBean Events   «Prev  Next»
Lesson 1

Purpose and Function of JavaBeans Events:

JavaBeans events are a mechanism for communication between objects in a Java program. They allow objects to notify other objects when a specific event occurs, such as a button being clicked or a text field being edited. JavaBeans events are based on the observer pattern, which is a design pattern that defines a one-to-many dependency between objects. In this pattern, an object (the subject) maintains a list of its dependents (the observers). When the subject's state changes, it notifies all of its observers, which can then update their own state accordingly.
In JavaBeans, the subject is called the event source, and the observers are called event listeners. The event source is the object that generates the event, and the event listener is the object that receives the event and responds to it. JavaBeans events are used to communicate a wide variety of information between objects. For example, a button might generate an event when it is clicked, a text field might generate an event when its text is changed, and a menu might generate an event when an item is selected.

Roles of Event Listeners, Event Sources, and Event Adapters:

  1. Event Listeners: Event listeners are objects that implement an interface that defines the methods that will be called when an event occurs. For example, a button might have an event listener that implements the ActionListener interface, which defines the actionPerformed method. When the button is clicked, the actionPerformed method will be called.
  2. Event Sources: Event sources are objects that generate events. They maintain a list of event listeners and notify them when an event occurs. For example, a button is an event source that generates an ActionEvent when it is clicked.
  3. Event Adapters Event adapters are objects that adapt one event type to another. This can be useful when you want to use an event listener that is designed for a different type of event. For example, you might use an event adapter to adapt a MouseEvent to an ActionEvent so that you can use the same event listener for both types of events.:

JavaBeans events are a powerful mechanism for communication between objects in a Java program. They can be used to create a wide variety of applications, including graphical user interfaces (GUIs), web applications, and enterprise applications.


Module learning objectives

This mdoule will discuss event listeners and event sources, as well as event adapters. You will also learn how events are delivered. Toward the end of the module you will use the BeanBox to connect Beans together with events. After completing the module, you will have the knowledge and skills necessary to:
  1. Register event listeners to receive Bean events
  2. Handle Bean events broadcast to event listeners
  3. Use the BeanBox to connect Beans together with events

SEMrush Software
The JEE platform defines JavaBeans for component architectures
  1. Conventions for how software components interact
  2. Some built-in Java classes

Example Component Architecture

Personal Web Application
Personal Web Application MVC 1

Personal Web Application MVC 2
Personal Web Application MVC 2

In the next lesson, you learn about two event types: low-level and semantic.