Event Handling PDF
Event Handling PDF
Event Handling PDF
Event handling
Listener
This class listens for the events in the application. It controls the application without affecting
its internal mechanism.
The Listener interfaces check the continuity of the work, the dispatching of a class must be
able to rely on each of its listeners to contain the method that is executed when the event
occurs. It can be easily done in Java by the use of an Interface class. The important point is
that a class, which is going to be a listener, must implement that interface. They are:
ServletContextListener and
HttpSessionListener.
When a listener is created, by the property of the interface "all the methods of that interface
must be implemented". Some listeners, like the ActionListener, have only one method.
Event Handling
The Abstract Window Toolkit (AWT) uses event driven programming to do processing of user
actions, one that underlies all modern window systems programming. Within the AWT, all
user actions belong to an abstract set of things called events. An event describes, in sufficient
detail, a particular user action. Rather than the program actively collecting user-generated
events, the Java run time notifies the program when an interesting event occurs. Programs
that handle user interaction in this fashion are said to be event driven.
Event Handling
Event Handling provides four types of classes; they are:
Event Adapters
Event classes
Event Sources
Event Listeners
1. Event Adapters
In a program, when a listener has many abstract methods to override, it becomes complex for
the programmer to override all of them.
For example, for closing a frame, we must override seven abstract methods of
WindowListener, but we need only one method of them.
For reducing complexity, Java provides a class known as "adapters" or adapter class. Adapters
are abstract classes, that are already being overriden.
2. Event classes
Every event source generates an event and is named by a Java class. An event is generated
when something changes within a graphical user interface.
For example the event generated by a:
Button is known as an ActionEvent
Checkbox is known as an ItemEvent
All the events are listed in the java.awt.event package.
3. Event Sources
Event Sources are responsible for generating events and are called components.
The source for an event can be a button, TextField or a Frame etcetera.
Event Listeners
WindowEvent WindowListener
ComponentEvent ComponentListener
ContainerEvent ContainerListener
FocusEvent FocusListener
Reference
1. Mahesh Bhave and Sunil Patekar, "Programming with Java", First Edition, Pearson
Education,2008, ISBN:9788131720806
2. Herbert Schildt, The Complete Reference C++, 4th Edition, Tata McGraw Hill, 2003.
3. Stanley B.Lippmann, Josee Lajore, C++ Primer, 4th Edition, Pearson Education, 2005.
4. Rajkumar Buyya,S Thamarasi selvi, xingchen chu, Object oriented Programming with java,
Tata McGraw Hill education private limited.
5. Richard A Johnson, Introduction to Java Programming and OOAD, CENGAGE Learning.
6. E Balagurusamy, Programming with Java A primer, Tata McGraw Hill companies.
7. Sourav Sahay, Object Oriented Programming with C++ , 2nd Ed, Oxford University
Press,2006 (Chapters 1, 2, 4)
8. Herbert Schildt, Java The Complete Reference, 7th Edition, Tata McGraw Hill, 2007.
(Chapters 1, 2, 3, 4, 5, 6, 8, 9,10, 11, 21, 22, 29, 30)
9.www.c-sharpcorner.com
10.www.studytonight.com
11.www.javatpoint.com