EventDrivenProgramming

EventDrivenProgramming - object, which provides more data...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Event-driven Programs Event-driven Programs • When users interact with computer they generate events (e.g., moving/clicking the mouse, typing, etc.) • Can respond to events by having listener for events addMouseListeners() addKeyListerners() • Use Java library the deals with events: • Methods of a listener get called asynchronously when events occur Using portions of slides by Eric Roberts import java.awt.event.*; Responding to Mouse Events mouseClicked( e ) mousePressed( e ) mouseReleased( e ) mouseMoved( e ) mouseDragged( e ) Called when the user clicks the mouse Called when the mouse button is pressed Called when the mouse button is released Called when the user moves the mouse Called when the mouse is dragged with the button down The parameter e is MouseEvent
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: object, which provides more data about event, such as the location of mouse. • General steps: 1. init or run method should call addMouseListeners 2. Write definitions of any listener methods needed Using portions of slides by Eric Roberts Responding to Keyboard Events keyPressed( e ) keyReleased( e ) keyTyped( e ) Called when the user presses a key Called when the key comes back up Called when the user types (presses and releases) a key The parameter e is a KeyEvent object, which indicates which key is involved. • General steps: 1. init or run method should call addKeyListeners 2. Write definitions of any listener methods needed Using portions of slides by Eric Roberts MouseTracker Example...
View Full Document

This note was uploaded on 02/18/2010 for the course CS 106A taught by Professor Sahami,m during the Fall '08 term at Stanford.

Ask a homework question - tutors are online