WDD_lec_11 - Web Design & Development Lecture 11 Event...

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

View Full Document Right Arrow Icon
Web Design & Development Lecture 11
Background image of page 1

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

View Full DocumentRight Arrow Icon
Event Handling
Background image of page 2
GUI are Event Driven
Background image of page 3

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

View Full DocumentRight Arrow Icon
Events GUIs generate events when the user interacts with GUI For example, Clicking a button Moving the mouse Closing Window etc In java, events are represented by Objects These objects tells us about event and its source. Examples are ActionEvent (Clicking a button) WindowEvent (Doing something with window e.g. closing , minimizing) Both AWT and swing components (not all) generate events java.awt.event.*; javax.swing.event.*;
Background image of page 4
Some event classes of java.awt.event java.lang.Object java.awt.AWTEvent ActionEvent ItemEvent AdjustmentEvent java.util.EventObject ContainerEvent PaintEvent FocusEvent WindowEvent InputEvent MouseEvent Interfa ce nam e
Background image of page 5

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

View Full DocumentRight Arrow Icon
Event Handling Model Common for both AWT and Swing components Event Delegation Model Processing of an event is delegated to a particular object (handlers ) in the program Publish-Subscribe Separate UI code from program logic
Background image of page 6
Event Handling Steps For a programmer the event Handling is a three step process in terms of code Step 1 Create components which can generate events Step 2 Build component (objects) that can handle events (Event Handlers) Step 3 Register handlers with generators
Background image of page 7

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

View Full DocumentRight Arrow Icon
Event Handling Process [1] Event Generators You have already seen alot of event generators Buttons Mouse Key Window Etc JButton b1 = new JButton(“Hello”); Now b1 can generate events
Background image of page 8
Event Handling Process [2] Event Handlers/ Event Listener First Technique - By Implementing Listener Interfaces Java defines interfaces for every event type If a class needs to handle an event. It needs to implement the corresponding listener interface To handle “ActionEvent” a class needs to implement “ActionListener” To handle “KeyEvent” a class needs to implement “KeyListener” To handle “MouseEvent” a class needs to implement “MouseListener” And so on
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 33

WDD_lec_11 - Web Design & Development Lecture 11 Event...

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

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