lecture21

lecture21 - PIC 20A Lecture 21 Event Handling Events an...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
PIC 20A Lecture 21: Event Handling
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Events • an event is an interaction of the user with a GUI component • events are modeled in Java by event objects Examples – pressing a button ( ActionEvent ) – selecting a menu item ( ActionEvent ) – pressing a key ( KeyEvent ) – setting the focus on a component ( FocusEvent ) – clicking the mouse ( MouseEvent )
Background image of page 2
Events Store Information • every event has a source - the GUI component with which the user interacted • to access a reference to the source, use the getSource() method of the event object
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Responding to Events event handler - method which is called automatically in response to an event ActionEvent handler public void actionPerformed(ActionEvent e) must be defined if your class implements the event-listener interface ActionListener
Background image of page 4
event-listener interface ? • an interface containing abstract event handler method declarations for a particular event type eg ActionListener (ActionEvent) MouseListener (MouseEvent) MouseMotionListener (MouseMotionEvent) MouseWheelListener (MouseWheelEvent) KeyListener (KeyEvent) FocusListener (FocusEvent) ItemListener (ItemEvent)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 19

lecture21 - PIC 20A Lecture 21 Event Handling Events an...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online