Event handling:
The event class is middle to the Java window event-generation and handling mechanism. Event objects are produced through a user who interacts along with a java window program or applet and through the Java runtime system. User-produced events occur when users make selections on a menu or press a key. An Events generated through the runtime system involve exceptions and errors. They are handled predefined event- handling methods which are defined through the component class and their subclasses, those methods are overridden to perform custom event processing.
An event class defines numerous constants for identify the events which are defined for the AWT classes. It is most important in which you review these constants to become familiar along with the types of events which might required to be handled through your programs. You'll become aware of the general event handling performed for the several window components through working by the example programs.
The classes which represent events are at the core of Java's event handling mechanism. Therefore, we start our study of event handling along with a tour of the event classes. As you will see, they give a consistent and easy-to-use means of encapsulating events.
At the root of the java event class hieraracy is EventObject that is in java.util. It is the superclass for all events. java.util is one constructor is displays here:
EventObject(Object src)
Here, src is the object which produces this event.
EventObject holds two methods: getSource () and toString().The getSource()
Method returns the source of the event. Its common form is displays here:
Object getSource()
As expected, toString() will returns the string equivalent of the event.
The class AWTEvent, described inside the java.awt package, is a subclass of EventObject. This is the superclass(either directly or indirectly)of all AWT-based events used through the delegation event model. AWTEvent getID() method can be used to determine the type of the event. The signature of this function is display here:
int getID()
- For all events an EventObject is a superclass.
- For all AWT events AWTEvent is a superclass which are handled through the delegation event model.