Event Sources:
A source is an object which produces an event. That occurs when the internal state of that particular object modifies in a few way. Sources might produce more than one type of event.
A source must register listeners in sequence for the listeners to receive notifications about a specific type of event. Every type of event has its own registration method.
Here is the common form:
Public void addTypeListener(TypeListener el)
Above, Type is the name of the event and el is a reference to the event listener. For instance, the method which registers a keyboard event listeners is called addKeyListener(). A method which registers a mouse motion listener is called addMouseMotionListener(). Whenever an event occurs, all registered listeners are notified and receive a copy of the event object. That is known as multicasting the event. Within all cases, notifications are sent only to listeners to receive them.
A few sources might permit only one listener to register. The common form of such a method is this:
Public void addTypeListner(TypeListener el) Throws java.util.TooManyListnersException
Above, Type is the name of the event and el is a reference to the event listener. The registered listener is notified when such an event occurs,. This is known as unicasting the event.
A source must also give a method which permits a listener to unregister an interest in a specific type of event. The common form of such a method is this:
Public void removeTypeListener(TypeListener el)
Above, Type is the name of the event and el is a reference to the eventlistener. For instance, to remove a keyboard listener, you will call removeKeyListener().
The methods which add or remove listeners are provided through the source which produces events. For instance, the Component class gives methods to add and remove keyboard and mouse event listeners.