A
source is an object that generates an event. This occurs when the internal
state of that object changes in some way.
Sources
may generate more than one type of event.
A
source must register listeners in order for listener to receive notification
about a specific type of event.
Each
type of notification has its own registration method. The general form is shown
below:
public void addTypeListner
(TypeListner 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
().
When
an event occurs, all registered listeners are notified and receive a copy of
the event object. This is known as multicasting
the event.
Some
sources may allow only one listener to register. Its general form is:
public void
addTypeListner (TypeListner el) throws
java.util.TooManyListenersException
When some
event occurs, the registered listener is notified. This is known as unicasting the event.
A
source must also provide a method that allows a listener to unregister for a
specific type of event. Its general form is:
public
void removeTypeListner (TypeListner el)
Here, Type is
the name of the event, and el is a reference to the event listener. For
example, the method to remove a keyboard event listener is removeKeyListener ().
No comments:
Write comments