Events Chris Piech CS 106 A Stanford University
- Slides: 41
Events Chris Piech CS 106 A, Stanford University Piech, CS 106 A, Stanford University
Making Vegas 2. 0 Piech, CS 106 A, Stanford University
Catch Me If You Can Piech, CS 106 A, Stanford University
We’ve Gotten Ahead of Ourselves Piech, CS 106 A, Stanford University Source: The Hobbit
Start at the Beginning Piech, CS 106 A, Stanford University Source: The Hobbit
Learning Goals 1. Write a program that can respond to mouse events 2. Use an instance variable in your program Piech, CS 106 A, Stanford University
Listener Model • When users interact with computer they generate events (e. g. , moving/clicking the mouse) • Can respond to events by having listener for events add. Mouse. Listeners() • Listeners get control of the program when an event happens. Piech, CS 106 A, Stanford University Using portions of slides by Eric Roberts
Responding to Mouse Events 1. The run method should call add. Mouse. Listeners 2. Write definitions of any listener methods needed mouse. Clicked( e) mouse. Pressed( e) mouse. Released(e) mouse. Moved(e) mouse. Dragged(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 Mouse. Event object, which provides more data about event, such as the location of mouse. Piech, CS 106 A, Stanford University Using portions of slides by Eric Roberts
Example Piech, CS 106 A, Stanford University
Hole Puncher Piech, CS 106 A, Stanford University
Now With Dancing Children Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
Normal Program Run Method Piech, CS 106 A, Stanford University
New Listener Characters Mouse Listener Mouse Moved Method Piech, CS 106 A, Stanford University
Program with a Mouse Method Run Method Mouse Moved Method Piech, CS 106 A, Stanford University
Program Starts Running Run Method Mouse Moved Method Piech, CS 106 A, Stanford University
Add Mouse Listener Run Method Mouse Moved Method add. Mouse. Listeners(); Piech, CS 106 A, Stanford University Mouse Listener
Program Runs as Usual Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Mouse Moved! Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Calls Mouse Moved Method Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
When done, Run continues. Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Keeps Doing Its Thing… Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Mouse Moved! Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Calls Mouse Moved Method Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
When done, Run continues. Run Method Mouse Moved Method Piech, CS 106 A, Stanford University Mouse Listener
Mouse Tracker Piech, CS 106 A, Stanford University
Mouse Tracker Piech, CS 106 A, Stanford University
Instance Variables 1. Variables exist until their inner-most control block ends. 2. If a variable is defined outside all methods, its inner-most control block is the entire program! 3. We call these variables instance variables * Instance variables have special meanings in programs with multiple files. For now you need to know that all methods can see them and that their initialization line is executed before run. Piech, CS 106 A, Stanford University
Instance Variables + Events Often you need instance variables to pass information between the run method and the mouse event methods! Piech, CS 106 A, Stanford University
Null Objects have a special value called null which means this variable is not associated with a value yet. Piech, CS 106 A, Stanford University
Debris Sweeper Piech, CS 106 A, Stanford University
New Concepts New Commands • add. Mouse. Listeners(); • get. Element. At(x, y); • remove(obj); New Ideas • The Listener Model • Instance Variables • null Piech, CS 106 A, Stanford University
Responding to Mouse Events 1. The run method should call add. Mouse. Listeners 2. Write definitions of any listener methods needed mouse. Clicked( e) mouse. Pressed( e) mouse. Released(e) mouse. Moved(e) mouse. Dragged(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 Mouse. Event object, which provides more data about event, such as the location of mouse. Piech, CS 106 A, Stanford University Using portions of slides by Eric Roberts
Responding to Keyboard Events 1. The run method should call add. Key. Listeners 2. Write definitions of any listener methods needed key. Pressed( e) key. Released( e) Called when the user presses a key Called when the key comes back up key. Typed(e) Called when the user types (presses and releases) a key The parameter e is a Key. Event object, which indicates which key is involved. Piech, CS 106 A, Stanford University Using portions of slides by Eric Roberts
And Here We Are… Piech, CS 106 A, Stanford University
Catch Me If You Can? Piech, CS 106 A, Stanford University
- Chris piech
- Chris piech stanford
- Karolina piech
- Karolina piech
- Mutually exclusive events vs not mutually exclusive events
- Stanford security awareness
- Stanford university continuing education
- Stanford university
- Steve jobs stanford commencement address
- Dan boneh stanford
- Dr ash standford
- Silicon valley stanford university
- Cs223 stanford
- Stanford university
- Claudia arrighi
- National and kapodistrian university of athens events
- University of health sciences lahore events
- Seoul national university events
- 106 spelled out
- Fahrenheit 451 pages 76-89 summary
- Nick troccoli
- Irig 106 chapter 10
- Mae 106
- Plt 106
- 106 pal
- 106 signal brigade
- Error n-106
- Section 106 compliance
- Salmo 106
- Fas 87
- Kj 106
- Tc 106
- Iat 106
- Lesson 2 estimate products
- Roberts building 106
- 456x42
- 生命聖詩106
- 101 102 103 104 105 106 107 108
- 106
- Sqte-106
- 105×106
- Glucosio 106 a digiuno