GoCoding.org

Java Event Classes

by | Aug 7, 2021 | Java

Java Event Classes

The literal term of the word ‘event’ signifies a particular action that triggers some response.  Such an action brings about a change in the current scenario of things. In Java as well, an event is defined as the process which brings about a change in the state of an object. Some of the most common events in Java are clicking of a button or dragging the mouse cursor to perform some action. Every event is thereafter followed by a Listener interface which performs an action in response to the event. The java.awt.event package provides several event classes and listener interfaces that can be used to perform event handling.

Java Event Classes and Listener Interfaces

Event ClassesListener Interfaces
ActionEventActionListener
MouseEventMouseListener and MouseMotionListener
MouseWheelEventMouseWheelListener
KeyEventKeyListener
ItemEventItemListener
TextEventTextListener
AdjustmentEventAdjustmentListener
WindowEventWindowListener
ComponentEventComponentListener
ContainerEventContainerListener
FocusEventFocusListener

 

Steps to Perform Event Handling

To be able to handle a Java event successfully, the following step have to be carried out:

The primary requirement is to register the event component of your code with a Listener such that your program knows how to respond to an event.

Registration Methods

  • Button – public void addActionListener (ActionListener a) {}
  • MenuItem – public void addActionListener (ActionListener a) {}
  • TextField – public void addActionListener (ActionListener a) {}
  • TextField – public void addTextListener (TextListener a) {}
  • TextArea – public void addTextListener (TextListener a) {}
  • Checkbox – public void addItemListener (ItemListener a) {}
  • Choice – public void addItemListener (ItemListener a) {}
  • List – public void addActionListener (ActionListener a) {}
  • List – public void addItemListener (ItemListener a) {}

 

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.