0% found this document useful (0 votes)
8 views4 pages

Event Handling

The document explains the delegation event model, which involves a source generating events that are processed by registered listeners. It details the roles of event sources, listeners, and the use of adapter classes to simplify event handling. Additionally, it covers regular expressions, including the Pattern and Matcher classes for performing pattern matching operations.

Uploaded by

suprajasangitrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Event Handling

The document explains the delegation event model, which involves a source generating events that are processed by registered listeners. It details the roles of event sources, listeners, and the use of adapter classes to simplify event handling. Additionally, it covers regular expressions, including the Pattern and Matcher classes for performing pattern matching operations.

Uploaded by

suprajasangitrao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Event Handling:

1. The Delegation event model:


• Delegation event model defines standard and consistent
mechanisms to generate and process events
• Its concept is quite simple: a source generates an event and sends it
to one or more listeners. The listener simply waits until it receives
an event. Once an event is received, the listener processes the event
and then returns.

Events:
• Def: In the delegation model, an event is an object that describes
change of state in a source.
• an event can be generated when a person interacts with the
elements in a graphical user interface.
• Some of the activities that cause events to be generated are
pressing a button, entering a character via the keyboard, selecting
an item in a list, and clicking the mouse.

Event Sources :
• A source is an object that generates an event.
• A source must register listeners in order for the listeners to receive
notifications about a specific type of event.
• Each type of event has its own registration method. Here is the
general form:
public void addTypeListener (TypeListener el )
• Here, Type is the name of the event, and el is a reference to the
event listener.
• For example, the method that registers a keyboard event listener is
called addKeyListener( ). The method that registers a mouse
motion listener is called addMouseMotionListener( ).

Event Listeners:
• A listener is an object that is notified when an event occurs.
• It has two major requirements.
• First, it must have been registered with one or more sources to
receive notifications about specific types of events.
• Second, it must implement methods to receive and process these
notifications.
• The methods that receive and process events are defined in a set of
interfaces, such as those found in java.awt.event.

Event Class:
• The classes that represent events are at the core of Java’s event
handling mechanism. Thus, a discussion of event handling must
begin with the event classes

Handling Mouse Events:

To handle mouse events, you must implement the MouseListener and the
MouseMotionListener interfaces.

write code

Handling Key Events:

Write code
Adapter class:

• Java provides a special feature, called an adapter class, that can


simplify the creation of event handlers in certain situations.
• An adapter class provides an empty implementation of all methods
in an event listener interface
• Adapter classes are useful when you want to receive and process
only some of the events that are handled by a particular event
listener interface.
• You can define a new class to act as an event listener by extending
one of the adapter classes and implementing only those events in
which you are interested.

Regular Expressions:
• a regular expression is a string of characters that describes a character
sequence.
• The regular expression package lets you perform sophisticated pattern
matching operations.
• Regular expressions can specify wildcard characters, sets of characters,
and various quantifiers.
• There are two classes that support regular expression processing: Pattern
and Matcher. These classes work together.
• Use Pattern to define a regular expression. Match the pattern against
another sequence using Matcher.

Pattern:
The Pattern class defines no constructors. Instead, a pattern is created by
calling the compile( ) factory method. One of its forms is shown here:
static Pattern compile(String pattern)

Matcher:
The Matcher class has no constructors. Instead, you create a Matcher by
calling the matcher( ) factory method defined by Pattern

You might also like