Lecture 8.5 Animating with EventTimer. © 2006 Pearson Addison-Wesley. All rights reserved 8.5.2 A Crash Course in the Use of Timed Events What kinds of.

Slides:



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

JFrame JComponent JFrame JComponent JFrame JComponent.
© 2006 Pearson Addison-Wesley. All rights reserved Inheritance When one class inherits another class, the new class becomes a specialized version.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Chapter 15 Geography, Climate, and Natural Resources.
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.
Chapter 2 Application Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 2-2.
Event Handling Events and Listeners Timers and Animation.
Chapter 13 Income Inequality. Copyright © 2005 Pearson Addison-Wesley. All rights reserved
Chapter 1 The Facts to Be Explained. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
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.
Chapter 1 Computer Networks and the Internet. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 1-2.
Chapter 6 Wireless and Mobile Networks. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 3 Transport Layer. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 3-2.
Lecture 19 Graphics User Interfaces (GUIs)
Chapter 6 Human Capital. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 6-2.
Chapter 8 The Role of Technology in Growth. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 8-2.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
Chapter 7 Multimedia Networking. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. 7-2.
Chapter 16 Resources and the Environment at the Global Level.
Object-Oriented Programming in Java. Object-Oriented Programming Objects are the basic building blocks in an O-O program. – A program consists of one.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
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.
GUI programming Graphical user interface-based programming.
SIGCSE’11 - Workshop #3Pedagogical Progressions for Teaching OOD Computer Science & Engineering Carl Alphonce A Progression of Events.
Lecture 5.2 Primitive Expression Patterns. © 2006 Pearson Addison-Wesley. All rights reserved A pattern is a general template that can be applied.
Java Event Handling CSIS 3701: Advanced Object Oriented Programming.
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
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.
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
© 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 )
Lecture 9.4 Java Interfaces. © 2006 Pearson Addison-Wesley. All rights reserved Java does not support multiple inheritance. Interface Characteristics...
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Enhanced Car Payment.
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.
© 2006 Pearson Addison-Wesley. All rights reserved Design by Prototype Programmers often approach a problem by creating a series of prototypes. Each.
© 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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 28.1 Java Speech API 28.2 Downloading and.
MIT AITI 2004 Swing Event Model Lecture 17. The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Component-Based Software Engineering GUI Basics Paul J Krause.
Lecture 15.1 Event Delegation.
Modular Event Handling
CompSci 230 S Programming Techniques
JButton Chapter 11 Lecture 3.
Prototyping with Methods
Animating with EventTimer
Lecture 9.5 Event Delegation.
Prototyping with Methods
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Introduction to Event Handling
Section 10.5 The Dot Product
...that can get messy when we have lots buttons!
Presentation transcript:

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 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 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(); } 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(); } 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 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(); }