Saturday, 1 February 2014

Event Handling

The event. Event handling is fundamental to Java programming because it is integral to the creation of applets and other types of GUI-based programs. 


The Delegation Event Model

The modern approach to handling events is based on the delegation event model, which 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.In this scheme, the listener simply waits until it receives an event. Once an event is received, the listener processes the event and then returns.
                         In the delegation event model, listeners must register with a source in order to receive an event notification. This provides an important benefit: notifications are sent only to listeners that want to receive them.an event was propagated up the containment hierarchy until it was handled by a component. 


Events


In the delegation model, an event is an object that describes a state change in a source. It can be generated as a consequence of a person interacting 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

Asourceis 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 the listeners to receive notifications about a specific type of event.



 Each type of event has its own registration method.:general Form:

public void addTypeListener(TypeListenerel)

Here, Typeis the name of the event, and el is a reference to the event listener.When an event occurs, all registered listeners are notified and receive a copy of the event object. This is known as multicasting the event. In all cases, notifications are sent only to listeners that register to receive them.

Some sources may allow only one listener to register. The general form of such a method is this:

public void addTypeListener(TypeListenerel)
throws java.util.TooManyListenersException

Here, Type is the name of the event, and el is a reference to the event listener. When such an 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 an interest in a specific type of event. The general form of such a method is this:

public void removeTypeListener(TypeListenerel)

Here, Typeis the name of the event, and el is a reference to the event listener.

Event Listeners


A listeneris 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.







































































































1 comment :

  1. Hi Thanks for the nice information its very useful to read your blog. We provide best Block Chain Services

    ReplyDelete