CS324e - Elements of Graphics and Visualization Timing Framework.

Slides:



Advertisements
Similar presentations
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Event Handling Events and Listeners Timers and Animation.
CSE 115 Week 5 February , Monday Announcements Exam 3 today Exam 3 today Lab 3 due this week Lab 3 due this week Exam 4 Monday 2/18 Exam.
Unit 12 Object-oriented programming: Event-driven programming for GUI Jin Sa.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L03 (Chapter 15) Creating.
GUI Programming in Java
Java Programming Chapter 10 Graphical User Interfaces.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
CS324e - Elements of Graphics and Visualization Checkerboard World.
Welcome to CIS 083 ! Events CIS 068.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
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.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Java GUI’s are event driven, meaning they generate events when the user interacts with the program. Typical events are moving the mouse, clicking a mouse.
Session 11 Border Layout, using Panels, Introduction to PinBallGame.
(c) University of Washington07b-1 CSC 143 Java Events, Event Handlers, and Threads Reading: Ch. 17.
Session 10 CannonGame and Event-driven Programming.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
1 CSC111H Graphical User Interfaces (GUIs) Introduction GUIs in Java Understanding Events A Simple Application The Containment Hierarchy Layout Managers.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Graphical User Interfaces (Part 2) 1. View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
1 / 67 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 14 Programming Fundamentals using Java 1.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
Week 6: Basic GUI Programming Concepts in Java Example: JFrameDemo.java container : a screen window/applet window/panel that groups and arranges components.
Object Oriented Programming.  Interface  Event Handling.
Session 13 Pinball Game Construction Kit (Version 3):
Introduction to visual programming C#. Learning Outcomes In this chapter, you will learn about :  Event-Based Programming  The Event Based Model  Application.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Review_6 AWT, Swing, ActionListener, and Graphics.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Java Swing One of the most important features of Java is its ability to draw graphics.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Animation in Java Disclaimer Rendering Performance Rendering or Performance issues are not covered here.
Swing GUI Components So far, we have written GUI applications which can ‘ draw ’. These applications are simple, yet typical of all Java GUI applications.
Lesson 28: More on the GUI button, frame and actions.
View  view  presents the user with a sensory (visual, audio, haptic) representation of the model state  a user interface element (the user interface.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Swing Timers A Swing timer fires one or more action events after a specified delay. You can use Swing timers in two ways:  To perform a task once, after.
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit7: Event-driven programming 1.
A Quick Java Swing Tutorial
CSC 205 Programming II Lecture 5 AWT - I.
Graphical User Interfaces
CompSci 230 S Programming Techniques
MOM! Phineas and Ferb are … Aims:
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Event-driven programming for GUI
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
EE 422C Java FX.
Chapter 15 Event-Driven Programming and Animations
Chapter 15 Event-Driven Programming and Animations
Events, Event Handlers, and Threads
Constructors, GUI’s(Using Swing) and ActionListner
Border Layout, using Panels, Introduction to PinBallGame
Tonga Institute of Higher Education
CSC 221: Introduction to Programming Fall 2018
Presentation transcript:

CS324e - Elements of Graphics and Visualization Timing Framework

Animating Swing Based Programs From FRC goal: provide framework and library to allow animation of components in a GUI Set of utility classes that contain the code common to handling timing issues for animation more functionality than the javax.swing.timer class 2

Example - Fading Button When button clicked it fades out and then back in fading cycle repeats until the button is pressed again 3

Fading Button Classes JFrame to hold panel and button checkerboard is a JPanel Button is a FadingButtonTF – class extends the JButton class – implements ActionListener (instead of using an anonymous inner class) and TimingTarget interfaces 4

FRC Timing Framework Handle common tasks such as determining what fraction of the animation has been completed Provide a simple API (Application Programming Interface) – a way of using existing code in a simple way – We have been using the Java API 5

Core Concepts of FRC Timing Framework handles timing, but alteration left to the programmer Animator – class that contains most of the timing functionality callbacks (listeners) – similar to timer callbacks but with more types of callbacks and more information 6

Core Concepts Duration: length of time animation runs, or can be set to indefinite (a clock for a game) Repetition: timer can run once and stop or repeat over and over Resolution: frame rate or frames per second – how often does timer send out notifications – default is 20 fps 7

Core Concepts Starting and Ending behaviors: – may add delay to start or begin in the middle of a repetition Interpolation – default is linear interpolation – fractions based on elapsed time / total time – possible to have other kinds of interpolation – start and end slowly (ease in and out) 8

Example Program Class declaration and instance variables 9

Example Program Constructor with creation of Animator 10

Animator Properties duration in milliseconds – can set to Animator.INFINITE to run continuously repeatCount – number of times to run, can also be INFINITE repeatBehavior: LOOP or REVERSE target: listener for timer notifications 11

Loop vs. Reverse 12 time fraction from Animator LOOP time fraction from Animator REVERSE

Animator Properties 13 time fraction from Animator REVERSE

Controlling the Animator methods for Animator Object void start() – callbacks to start and timingEvent methods void stop() – callback to end method void cancel() – stops Animator, but no callbacks void pause() void resume() boolean isRunning() 14

Fading Button Demo Respond to button clicks recall the FadingButtonTF class implements the ActionListener interface 15

Responding to Notifications To respond to notifications from the animator create a class that implements the timing 16

Alteration of Button 17

Non Linear Interpolation Animator objects have acceleration and deceleration properties by default these are not used can set so animation eases in and / or out instead of fraction of animation being linear with respect to time elapsed 18

Set Acceleration and Deceleration represented as fraction of animation to accelerate to average speed and decelerate to stop sum of fractions must be <= 1 19

Linear Horizontal axis is time Vertical axis is fraction 20

Acceleration and Deceleration.3 of duration for acceleration.3 of duration for Deceleration note, at 1 second (1/4 of time) fraction is still below

Acceleration and Deceleration.7 of duration for acceleration.2 of duration for Deceleration 22

Triggers Part of FRC Timing Framework Start animation based on a specified event – for example: – user presses a button – user clicks on a door in a game – car in a game goes off the track in a game 23

Triggers Respond to – GUI events – time events – custom events created by the programmer Use triggers by: – create trigger including information about the Animator the trigger will run – add listeners to respond to trigger when it goes off 24

Triggers in Action Firing: when trigger event occurs the Animator objects start Disarming: canceling a trigger Auto-reverse: trigger has ability to run Animator forwards and then backwards – like the button fading in and out 25

Trigger Classes Trigger: base case for more complicated triggers TriggerEvent: part of framework to make it easy to add different kinds of Triggers ActionTrigger: simplest kind of Trigger – responds to java.awt.event.ActionEvent (like button clicks) 26

Trigger Demo Spheres fall and bounce based on various triggers The spheres are in their own panels, placed side by side 27

Trigger Types Program demos 5 different kinds of triggers Yellow Sphere - ActionTrigger when the Trigger button is clicked the yellow ball's animation runs restarts if button clicked again before animation complete action is the SpherePanel for the Yellow sphere 28

Animator for SpherePanel The FRC timing framework includes a class to automate alteration aspect of animations – PropertySetter From SpherePanel Creates animator 29

More on PropertySetter Note the PropertySetter.createAnimator method duration, object that has property animated, name of property (must have set… method), values property takes (y coordinate -> top, bottom, top) 30

Focus Trigger Blue Sphere - A FocusTrigger When the Trigger Button gains the focus (not pressed) the Blue Sphere bounces demo: use tab to change focus between Trigger button and Other Button 31

MouseTriggers Two MouseTriggers in the demo Red Sphere - armed trigger When the mouse is pressed on the button the red sphere bounces press and hold button change from triggerButton to action panel 32

MouseTrigger Green Sphere - MouseTrigger Activated when the mouse enters the Trigger button region – does not need to be pressed 33

Timing Trigger Gray Sphere - TimingTrigger When the action trigger (yellow sphere) stops then the timing trigger for the silver sphere starts useful for chaining animations Add triggers so when gray sphere stops, red, green, and blue bounce 34