{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

EventDrivenProgramming

EventDrivenProgramming - object which provides more data...

Info icon This 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
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern