what is event handling in java

11 months ago 16
Nature

Event handling in Java is the mechanism that controls an event and decides what should happen if an event occurs. An event can be defined as changing the state of an object or behavior by performing actions, such as a button click, cursor movement, keypress through the keyboard, or page scrolling. Java uses the Delegation Event Model to handle events, which defines the standard mechanism to generate and handle events. The Delegation Event Model has two key participants: the source, which is an object on which the event occurs and is responsible for providing information about the occurred event to its handler, and the listener, which is responsible for generating a response to an event. The listener waits until it receives an event, processes the event, and then returns. The steps involved in event handling include the user clicking the button and generating the event, the object of the concerned event class being created automatically, and the information about the source and the event getting populated within the same object. There are two types of events in Java: foreground events and background events. Foreground events are generated due to interaction by the user on components in Graphic User Interface (GUI), such as clicking on a button, scrolling the scroll bar, cursor movements, etc. . Background events, on the other hand, do not require interactions of users to generate and are known as operating system failures/interrupts, operation completion, etc. . The java.awt.event package can be used to provide various event classes.