Q1. Discuss the types of Event Handling in Java ?
Or Describe the Delegation Event Model of Event Handling in Java. How is it a better approach than the other approach ?
Ans. There are two types of models for handling events :Delegation Event Model in java:
In the delegation event model, specific objects are designated as event handlers for GUI components. Event handling is the mechanism that controls the event and decides what should happen if an event occurs.This mechanism is known as event handler. Java uses the Delegation Event Model to handle the events. It defines standard and consistent mechanisms to generate and process events.
Delegation Event model has quite simple concept i.e. a source generates an event and sends it to one or more listeners. The key participants of delegation event model of event handling are:
(a) Source: An event source is an object which originates or "fires" event.
(b) Listener: It is an object that generate responses for a specific event.
(c) Object: An object describe the event for a particular class.
It is a better approach than the other approach because it posses the application logic completely separated from the user interface. In this model, listeners needs to be registered with the source object so that the listener can receive the event notification. This is one of the efficient way of handling the event.
2. Inductance Event Model in java:
In inheritance event handling, there is a widget Class that has a method for each type of input event.public class Widget
{
methods and members for Bounds
public void mouse Pressed (int x, int y, int button Number)
{ default behavior }
public void mouseReleased (intx, int, y, int buttonNumber)
{ default behavior }
public void mouseMoved (in x, int y)
{ default behavior }
public void keyPressed (char c, int x, int y, int modifiers)
{ default behavior }
public void windowClosed()
{ default behavior }
public void redraw (Graphics toDraw)
{ default behavior }
and a host of other event methods
}
Implementation of Inheritance Event Handling :
An important concept in inheritance event handling is in how an event method invocation is associated with the right code to handle that event. In this model each object had a reference to a class definition and each method had a name.This simple mechanism allowed subclasses to override event methods and provide code to handle the event in the unique manner required by the widget. It also allowed the windowing system to have a pointer to an object and send it the event mouseDown without knowing the object's class or what code would handle the mouseDown event.
Join us on Facebook and Twitter to get the latest study material. You can also ask us any questions.
Facebook = @ studywow
(click on it or search "studywow" on facebook)
Twitter = @ studywow
(click on it or search "studywow" on Twitter)
Email= studywow.com@gmail.com
Send us your query anytime!
Event Handling in Java, Delegation Event Model in java and Event Handling types in java.