WDD_lec_13 - Web Design Development Lecture 13 Event...

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

View Full Document Right Arrow Icon
Lecture 13
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 part 3
Background image of page 2
Handling Window Events Example Revisited
Background image of page 3

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

View Full DocumentRight Arrow Icon
Window Exit Handler Example Reveisted // Event Handlers for WindowListener public void windowActivated (WindowEvent we) { } public void windowClosed (WindowEvent we) { } public void windowClosing (WindowEvent we) { JOptionPane.showMessageDialog(null, “Good Bye”); System.exit(0) } public void windowDeactivated (WindowEvent we) { } public void windowDeiconified (WindowEvent we) { } public void windowIconified (WindowEvent we) { } public void windowOpened (WindowEvent we) { }
Background image of page 4
Last Code Example Problem Interested in windowClosing method only But have to provide definitions of all the methods, Why ? Because a class implementing an interface has to provide definitions of all methods present in that interface. Solution Use Adapter classes
Background image of page 5

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

View Full DocumentRight Arrow Icon
Adapter Classes
Background image of page 6
Adapter Classes For listener interfaces containing more than one event handling methods, jdk defines adapter classes. Examples are For WindowListener WindowAdapter For MouseMotionListener MouseMotionAdapter and many more Adapter classes provides definitions for all the methods (empty bodies) of their corresponding Listener interface It means that WindowAdapter class implements WindowListener interface.
Background image of page 7

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

View Full DocumentRight Arrow Icon
Adapter Classes public interface MouseMotionListener { public void mouseDragged (MouseEvent me); public void mouseMoved (MouseEvent me); } public class MouseMotionAdapter impelments MouseMotionListener { public void mouseDragged (MouseEvent me) { } public void mouseMoved (MouseEvent me) { } }
Background image of page 8
How to use Adapter Classes Previously handler class need to implement interface public class EventsEx implements MouseMotionListener { …. } Therefore it has to provide definitions of all the methods inside that interface
Background image of page 9

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

View Full DocumentRight Arrow Icon
How to use Adapter Classes Now our handler class will inherit from adapter
Background image of page 10
Image of page 11
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/01/2010 for the course CS CS506 taught by Professor mr. umair javed during the Spring '10 term at Virtual University of Pakistan.

Page1 / 35

WDD_lec_13 - Web Design Development Lecture 13 Event...

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

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