Animating with EventTimer

Slides:



Advertisements
Similar presentations
Web Design & Development Lecture 19. Java Graphics 2.
Advertisements

JFrame JComponent JFrame JComponent JFrame JComponent.
Events CSC 171 FALL 2001 LECTURE 9. History: the ABC John Vincent Atanasoff, with John Berry, developed the machine we now call the ABC -- the.
Event Handling Events and Listeners Timers and Animation.
Starts to load image Delay on network Load some more of the image Time for some word processing Thread 2 Thread 1 Figure 15.1 Two threads sharing the processor.
Lecture 19 Graphics User Interfaces (GUIs)
Object-Oriented Programming in Java. Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one.
MIT AITI 2003 Lecture 17. Swing - Part II. The Java Event Model Up until now, we have focused on GUI's to present information (with one exception) Up.
SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Carl Alphonce A Progression of Events.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
EVENTS Wiring together objects, code, and actions.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
CS1054: Lecture 21 - Graphical User Interface. Graphical User Interfaces vs. Text User Interface.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Anonymous Classes An anonymous class is a local class that does not have a name. An anonymous class allows an object to be created using an expression.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Practical Session 10: Animation. Animation kinds There are three basic kinds of animation: 1. Moving object 2. Changing pictures 3. Combination of 1 and.
Graphical User Interfaces A Graphical User Interface (GUI) in Java is created with at least three kinds of objects: –components, events, and listeners.
Lecture 3.1 Using Graphics with JFrame. © 2006 Pearson Addison-Wesley. All rights reserved javax.swing.JFrame - int x - int y - int width - int.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 4 – Completing the Inventory Application.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 5.1 Test-Driving the Enhanced Inventory Application.
© 2006 Pearson Addison-Wesley. All rights reserved Non-void Methods Parameters are largely one-way communication.  Shared instances variables is.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
1/18H212Mouse and Timer Events H212 Introduction to Software Systems Honors Lecture #16: Mouse and Timer Events October 26, 2015.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 17.1 Test-Driving the Student Grades Application.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lecture 4.1 More About Methods - Using a Prototyping Approach.
Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved A Crash Course in the Use of Timed Events What kinds of.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Lecture 15.1 Event Delegation.
Modular Event Handling
JButton Chapter 11 Lecture 3.
Prototyping with Methods
Chapter 1 Functions Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Lecture 9.5 Event Delegation.
How to Design Supplier Classes
Chapter 2 Limits Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Prototyping with Methods
Chapter 17 Linked Lists.
Chapter 19 Binary Search Trees.
11.7 Motion in Space Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 4 Inheritance.
Chapter 1 Preliminaries.
Chapter 14 Graphs and Paths.
Introduction to Event Handling
Chapter 10 Datapath Subsystems.
11.8 Length of Curves Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 20 Hash Tables.
Copyright © 2011 Pearson Education, Inc
Recursion (part 1) October 24, 2007 ComS 207: Programming I (in Java)
Searching for Guinea Pig B: Case Study in Online Research
Chapter 1 Functions Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Chapter 5 Algorithm Analysis.
The Facts to Be Explained
Instructor: Alexander Stoytchev
Alternate Proofs of Selected HO Theorems
Introduction: Some Representative Problems
Section 10.5 The Dot Product
Circuit Characterization and Performance Estimation
The Classical Model with Many Goods
Chapter 2 Part 1 Data and Expressions.
Chapter 6 Dynamic Programming.
Chapter 2 Reference Types.
...that can get messy when we have lots buttons!
Chapter 4 Greedy Algorithms.
Copyright © 2011 Pearson Education, Inc
Presentation transcript:

Animating with EventTimer Lecture 8.5 Animating with EventTimer

A Crash Course in the Use of Timed Events What kinds of occurrences produce events? How does the event handling mechanism work? © 2006 Pearson Addison-Wesley. All rights reserved

EventTimer for building computer “alarm clocks” javax.swing.Timer EventTimer «constructor» + EventTimer(int) «update» + start() + stop() «event handler» + void actionPerformed( java.awt.event.ActionEvent ) time between consecutive events (in milliseconds) © 2006 Pearson Addison-Wesley. All rights reserved

public class Clock extends EventTimer { import java.awt.event.*; public class Clock extends EventTimer { private Driver theDriver; /** post: theDriver == d */ public Clock( Driver d, int t ) { super( t ); theDriver = d; } public void actionPerformed( ActionEvent e ) { theDriver.clockHasTicked(); import javax.swing.JFrame; public class Driver { private Clock animator; private Oval dot; private JFrame win; public Driver() { win = new JFrame(); win.setBounds(0,0,200,200); win.setLayout(null); win.setVisible(true); dot = new Oval(0, 0, 30, 30); win.add(dot, 0); win.repaint(); animator = new Clock(this, 50); animator.start(); } public void clockHasTicked() { if (dot.getX() > 195) dot.setLocation(0, 0); else dot.setLocation(dot.getX()+1, 0); dot.repaint(); © 2006 Pearson Addison-Wesley. All rights reserved