Java Event HandlingIn AWT components, we came to know everycomponent (except Panel and Label) generatesevents when interacted by the user like clicking overa button or pressing enter key etc. Listeners handlethe events. Let us know the style (or design pattern)Java follows to handle the events.The event handling involves three types of classes. 1. Event Sources 2. Event classes 3. Event Listeners1. Event SourcesEvent sources are components, subclasses ofjava.awt.Component, capable to generate events.The event source can be a button, TextField or aFrame etc.java.awt.ComponentAfter having the basic idea of Java AWT, let us knowhow many component classes exist with java.awtpackage.
2. Event classesAlmost every event source generates an event and isnamed by some Java class. For example, the buttongenerates ActionEvent and Checkbox generatesItemEvent. All events listed in java.awt.eventpackage. Following list gives a few components andtheir listeners.
3. Event ListenersThe events generated by the GUI components arehandled by a special group of classes known as"listeners". Listener is an interface. Everycomponent has its own listener, say,AdjustmentListener handles the events of scrollbarSome listeners handle the events of a fewcomponents. For example, ActionListener handlesthe events of Button, TextField, List and Menus.Listeners are from java.awt.event package.