The modifiers argument indicates which modifiers were pressed when the event occurred. event describes the change in state of source. The character equivalent (if one exists) is passed in ch. Event source send it to the registered listeners, As listener receives the event, it process the event and then return it. Event handling is prime to Java programming because it’s integral to the creation of applets and other sorts of GUI-based programs. All these event classes and listeners are present in java.awt.event package. There are three types of key events, which are identified by these integer constants: KEY_PRESSED, KEY_RELEASED, and KEY_TYPED. There are four types of component events. The type of event is specified by type. It defines four integer constants that can be used to identify any modifiers associated with an action event: An AdjustmentEvent is generated by a scroll bar. The last event occurs only when a character is generated. ComponentEvent is the superclass either directly or indirectly of ContainerEvent, FocusEvent, KeyEvent, MouseEvent, and WindowEvent. An AdjustmentEvent is generated by a scroll bar. The triggersPopup flag indicates if this event causes a pop-up menu to appear on this platform. Listener listens to event. The WindowEvent class defines integer constants that can be used to identify them. The coordinates of the mouse are passed in x and y. An event source generates the event. MouseEvent(Component src, int type, long when, int modifiers, int x, int y, int clicks, boolean triggersPopup). An ActionEvent is generated when a button is pressed, a list item is double-clicked, or a menu item is selected. Whenever an event occurs, listeners gets notified. ContainerEvent is a subclass of ComponentEvent. Some activities that cause events to be generated are pressing a button, entering a personality via the keyboard, selecting an item during a list, and clicking the mouse.
Second, it implements methods to receive and process these notifications. In Java java.awt.Component specifies the components that may or may not generate events. An interface element is in a position to “delegate” the processing of an occasion to a separate piece of code. These are generated by text fields and text areas when characters are entered by a user or program. The current state of that item is in the state.
In addition to these graphical user interface elements, any class derived from Component, such as Applet, can generate events. Event listener listens the event generated on components and performs the corresponding action. Event Handling is managed by below mentioned aspects : Below are the list of event classes and listener interface present in Java : There are three components in Event Handling , as mentioned below : As discussed earlier, Events are simply change in state of object in java. Whenever the user clicks the button an event is generated. It is the process of handling events in Java. Here, src is a reference to the component that generated this event.
For example, an occasion could also be generated when a timer expires, a counter exceeds a worth, a software or hardware failure occurs, or an operation is completed.