CS106A, Stanford University

Slides:



Advertisements
Similar presentations
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Advertisements

TCU CoSc Programming with Java Handling Events.
CSI 3120, Exception handling, page 1 Exception and Event Handling Credits Robert W. Sebesta, Concepts of Programming Languages, 8 th ed., 2007 Dr. Nathalie.
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Event Handling Events and Listeners Timers and Animation.
Event Handling. In this class we will cover: Keyboard Events Mouse Events Focus Events Action Interface Multicasting.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
1 Exception and Event Handling (Based on:Concepts of Programming Languages, 8 th edition, by Robert W. Sebesta, 2007)
Welcome to CIS 083 ! Events CIS 068.
Chapter 11 Java AWT Part I: Mouse Events (Optional) Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
Lecture Set 13 Drawing Mouse and Keyboard Events Part B – Mouse and Keyboard Events.
Keyboard and Events. What about the keyboard? Keyboard inputs can be used in many ways---not just for text The boolean variable keyPressed is true if.
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
Dale Roberts GUI Programming using Java - Event Handling Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
CS350 – Windows Programming Formerly and more properly named: Event Driven Programming Dr. Randy Ribler.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
Computer Science 112 Fundamentals of Programming II Command Buttons and Responding to Events.
Concurrent Programming and Threads Threads Blocking a User Interface.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
CS-1020 Dr. Mark L. Hornick 1 Event-Driven Programming.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Understand the difference between applets and applications Identify meaningful applet resources for academic subjects Create and demonstrate a basic Java.
Object Oriented Programming.  Interface  Event Handling.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Event-Driven Programming 1.
Agenda Introduction. Event Model. Creating GUI Application. Event Examples.
COSC 4126 User Interaction User Interaction capturing and responding to input events.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
1 Chapter 3 Event-Driven Programming. 2 Objectives F To explain the concept of event-driven programming (§12.2). F To understand event, event source,
12-Jun-16 Event loops. 2 Programming in prehistoric times Earliest programs were all “batch” processing There was no interaction with the user Input Output.
 Onpress()  Videos loaded  Mouse click  Something that runs when a certain event occurs.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
GUI Programming using Java - Event Handling
Events and Event Handling
CompSci 230 S Programming Techniques
VAB™ for INFINITY Tutorial
Scratch for Interactivity
CHAPTER Reacting to the user.
Chapter 12 Event-Driven Programming
Keyboard Events keyboard acceleration TextFields
Mouse Event Handling in Java (Review)
More Events.
Responding to Events Event Handling in Java
Introduction to Event-Driven Programming
ActionScript Basics 2016 (2.0 – 3.0)
Event loops 16-Jun-18.
Unit 2 Getting Started With
Lesson 1: Buttons and Events – 12/18
CSE 331 Software Design and Implementation
Introduction to Events
Event Driven Programming
CS 106A, Lecture 14 Events and Instance Variables
Introduction to Computing Using Java
CSE 331 Software Design and Implementation
Lesson 17: Building an App: Canvas Painter
Event loops.
More programming with "Processing"
Event loops 17-Jan-19.
Event loops 17-Jan-19.
Events, Event Handlers, and Threads
CS106A, Stanford University
Lesson 2: Selecting Cells, Rows, and Columns
Event loops 8-Apr-19.
JavaScript and Events CS Programming Languages for Web Applications
Event loops.
Chapter 15 Event-Driven Programming and Animations Part 2
Event loops.
Event loops 19-Aug-19.
JavaScript and Events CS Programming Languages for Web Applications
Presentation transcript:

CS106A, Stanford University Events Chris Piech CS106A, Stanford University

Making Vegas 2.0

Catch Me If You Can

We’ve Gotten Ahead of Ourselves Source: The Hobbit

Start at the Beginning Source: The Hobbit

Learning Goals Write a program that can respond to mouse events Use an instance variable in your program

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 addMouseListeners() Listeners get control of the program when an event happens. Using portions of slides by Eric Roberts

Responding to Mouse Events 1. The run method should call addMouseListeners 2. Write definitions of any listener methods needed 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 object, which provides more data about event, such as the location of mouse. Using portions of slides by Eric Roberts

Example

Hole Puncher

Now With Dancing Children

Normal Program Run Method

Normal Program Run Method

Normal Program Run Method

Normal Program Run Method

Normal Program Run Method

Normal Program Run Method

Normal Program Run Method

New Listener Characters Mouse Listener Mouse Moved Method

Program with a Mouse Method Run Method Mouse Moved Method

Program Starts Running Run Method Mouse Moved Method

Add Mouse Listener Run Method Mouse Moved Method Mouse Listener addMouseListeners();

Program Runs as Usual Run Method Mouse Moved Method Mouse Listener

Mouse Moved! Run Method Mouse Moved Method Mouse Listener

Calls Mouse Moved Method Run Method Mouse Moved Method Mouse Listener

When done, Run continues. Run Method Mouse Moved Method Mouse Listener

Keeps Doing Its Thing… Run Method Mouse Moved Method Mouse Listener

Mouse Moved! Run Method Mouse Moved Method Mouse Listener

Calls Mouse Moved Method Run Method Mouse Moved Method Mouse Listener

When done, Run continues. Run Method Mouse Moved Method Mouse Listener

Mouse Tracker

Mouse Tracker

Instance Variables Variables exist until their inner-most control block ends. If a variable is defined outside all methods, its inner-most control block is the entire program! 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.

Instance Variables + Events Often you need instance variables to pass information between the run method and the mouse event methods!

Null Objects have a special value called null which means this variable is not associated with a value yet.

Debris Sweeper

New Concepts New Commands addMouseListeners(); getElementAt(x, y); remove(obj); New Ideas The Listener Model Instance Variables null

Responding to Mouse Events 1. The run method should call addMouseListeners 2. Write definitions of any listener methods needed 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 object, which provides more data about event, such as the location of mouse. Using portions of slides by Eric Roberts

Responding to Keyboard Events 1. The run method should call addKeyListeners 2. Write definitions of any listener methods needed keyPressed( e) Called when the user presses a key keyReleased( e) Called when the key comes back up keyTyped(e) Called when the user types (presses and releases) a key The parameter e is a KeyEvent object, which indicates which key is involved. Using portions of slides by Eric Roberts

And Here We Are…

Catch Me If You Can?