Events

An event is an action taken by the user when interacting with a program. Some examples of user events are:

  • pressing a key on the keyboard
  • clicking the mouse at a particular area of the program's graphical user interface (GUI)
  • clicking a button in the GUI
  • dragging the scrollbar, etc.
Buttons, text fields, choice lists, text areas, scrollbars, etc. which are added to a GUI application (or applet) are known as GUI components.  Different user actions on the various GUI components generate different events. Each event is represented by the relevant object. The events have to handled appropriately based upon the program specification. The event handling code is responsible for executing and producing the desired results. The table below shows some of the common GUI components and the typical event objects they generate through user actions.

Gui Component Description Event Object
JButton A common button ActionEvent
JCheckBox A check box button ItemEvent
JRadioButton One of a group of radio buttons ActionEvent
JMenuItem A menu item ActionEvent
JComboBox Selection from a choice list ActionEvent, ItemEvent
JSlider Scrollbar function ChangeEvent
JTextField Plain text input field ActionEvent