Having given you a taste of how event handling works, we finish this chapter with an overview of the AWT event handling architecture.
As we briefly mentioned earlier, event handling in Java is object oriented, with all events descending from the EventObject class in the java .util package. (The common superclass is not called Event because that is the name of the event class in the old event model. Although the old model is now deprecated, its classes are still a part of the Java library.)
The Event Object class has a subclass AWTEvent, which is the parent of all AWT event classes.
Inheritance diagram of AWT event classes
Some of the Swing components generate event objects of yet more event types; these directly extend Event Object, not AWT Event.
The event objects encapsulate information about the event that the event source communicates to its listeners. When necessary, you can then analyze the event objects that passed to the listener object, as we did in the button example with the getSource and get Action Command methods.
Some of the AWT event classes are of no practical use for the Java programmer. For example, the AWT inserts Paint Event objects into the event queue, but these objects are not delivered to listeners. Java programmers don’t listen to paint events; they override the paint Component method to control repainting. The AWT also generates a numberof events that are needed only by system programmers, to provide input systems for ideographic languages, automated testing robots, and so on. We do not discuss these specialized event types.
Semantic and Low-Level Events
The AWT makes a useful distinction between low -level and semantic events. A semantic event is one that expresses what the user is doing, such as “clicking that button”; hence, an Action-Event is a semantic event. Low-level events are those events that make this possible. In the case of a button click, this is a mouse down, a series of mouse moves, and a mouse up (but only if the mouse up is inside the button area). Or it might be a keystroke, which happens if the user selects the button with the TAB key and then activates it with the space bar. Similarly, adjusting scrollbar is a semantic event, but dragging the mouse is a low-level event.
Here are the most commonly used semantic event classes in the java.awt.event package:
Five low-level event classes are commonly used:
Several of the AWT listener interfaces, namely, those that have more than one method, come with a companion adapter class that implements all the methods in the interface to do nothing. (The other interfaces have only a single method each, so there is no benefit in having adapter classes for these interfaces.) Here are the commonly used adapter classes:
Table below shows the most important AWT listener interfaces, events, and event sources.
The javax.swing.event package contains additional events that are specific to Swing components. We cover some of them in the next section
Event Handling Summary
This concludes our discussion of AWT event handling. The next chapter shows you how to put together the most common of the components that Swing offers, along with a detailed coverage of the events they generate.
Core Java Related Interview Questions
|J2EE Interview Questions||Core Java Interview Questions|
|JDBC Interview Questions||JSP Interview Questions|
|Android Interview Questions||JavaServer Faces (JSF) Interview Questions|
|Java collections framework Interview Questions||Java 8 Interview Questions|
|Java Collections Interview Questions||Java Exception Handling Interview Questions|
|Java Concurrency Interview Questions||Java Serialization Interview Questions|
|Java Programmer Interview Questions||Java Inheritance Interview Questions|
|Java IO Interview Questions||Object Oriented Programming in PHP Interview Questions|
Core Java Tutorial
An Introduction To Java
The Java Programming Environment
Fundamental Programming Structures In Java
Objects And Classes
Interfaces And Inner Classes
User Interface Components With Swing
Deploying Applications And Applets
Exceptions, Logging, Assertions, And Debugging
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.