Java GUI Programming: Understanding Event Handling, Listeners, and Event Classes, Slides of Computer Engineering and Programming

An introduction to event handling in java gui programming. It explains the concept of event-driven programming, the role of events and listeners, and the different types of user actions and their corresponding events. The document also covers the java awt event listener interfaces and their methods, as well as handling simple action events using the 'actionperformed' method. Additionally, it discusses alternative approaches to event handling using inner classes.

Typology: Slides

2011/2012

Uploaded on 07/11/2012

dhananad
dhananad 🇮🇳

4

(4)

39 documents

1 / 11

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
GUI Programming in Java:
Event Handling
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Java GUI Programming: Understanding Event Handling, Listeners, and Event Classes and more Slides Computer Engineering and Programming in PDF only on Docsity!

GUI Programming in Java:

Event Handling

Event-Driven Programming

 Procedural programming is executed in

procedural order.

 In event-driven programming, code is

executed upon activation of events.

Selected User Actions

Source Event Type User Action Object Generated

Click a button JButton ActionEvent

Click a check box JCheckBox ItemEvent, ActionEvent

Click a radio button JRadioButton ItemEvent, ActionEvent

Press return on a text field JTextField ActionEvent

Select a new item JComboBox ItemEvent, ActionEvent

Select an item from a List JList ListSelectionEvent

Window opened, closed, etc. Window WindowEvent

Mouse pressed, released, etc. Any Component MouseEvent

Key released, pressed, etc. Any Component KeyEvent

Java AWT Event

Listener Interfaces

 ActionListener

 AdjustmentListener

 ComponentListener

 ContainerListener

 FocusListener

 ItemListener

 KeyListener

 MouseListener

 MouseMotionListener

 TextListener

 WindowListener

 ListSelectionListener

All are in the java.awt.event or javax.swing.event package

All are derived from EventListener in the java.util package

NOTE: any object that will respond to an event must implement a listener interface.

Handling Simple Action Events

Implementing the listener interface

Registering the frame to be a listener for action events generated by the two buttons

The method for responding to an Action event.

Handling Simple Action Events –

a closer look at the event-handling method

actionPerformed is a method required for all ActionListeners

An Event object’s getSource() method returns a reference to the Component object that generated the event.

Example with

named inner

classes, one for

listening to each

button

Inner class has direct access to all members (even private) of the outer class

Example with anonymous inner classes, one for listening to each button