Chapter 15 Event-Driven Programming and Animations

Slides:



Advertisements
Similar presentations
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Advertisements

Review CSC 171 FALL 2004 LECTURE 21. Topics Objects and Classes Fundamental Types Graphics and Applets Decisions Iteration Designing Classes Testing and.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
Chapter 6: Graphical User Interface (GUI) and Object-Oriented Design (OOD) J ava P rogramming: Program Design Including Data Structures Program Design.
A.k.a. GUI’s.  If you want to discuss your Lab 2 grade come see me this week. ◦ Office: 436 ERB. One hour prior to class ◦ Open to Appointments MWF 
Multimedia- Microsoft PowerPoint
CDM105 Session 9 Macromedia FLASH MX 2004 Part 2 : Animation with Motion Tweening and Shape Tweening.
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
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.
Introduction to Windows Programming
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
Motion Tweening – Lesson 81 Motion Tweening Lesson 8.
Concurrent Programming and Threads Threads Blocking a User Interface.
Topics Introduction Scene Graphs
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Object Oriented Programming.  Interface  Event Handling.
Chapter 14 Abstract Classes and Interfaces. Abstract Classes An abstract class extracts common features and functionality of a family of objects An abstract.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 27 JavaBeans and.
CS324e - Elements of Graphics and Visualization Timing Framework.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
Java Programming: From Problem Analysis to Program Design, 3e Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Understanding Desktop Applications Lesson 5. Objective Domain Matrix Skills/ConceptsMTA Exam Objectives Understanding Windows Forms Applications Understand.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Understanding Desktop Applications Lesson 5. Understanding Windows Forms Applications Windows Forms applications are smart client applications consisting.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Event Driven (Asynchronous) Programming. Event handling in Unity Subclass a class that contains event handling methods, and then override those methods.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 7 Event-Driven Programming and Basic GUI Objects.
CSC 205 Programming II Lecture 5 AWT - I.
CompSci 230 S Programming Techniques
Java FX: Scene Builder.
Chapter 15 Event-Driven Programming and Animations
A First Look at GUI Applications Radio Buttons and Check Boxes
Topics Graphical User Interfaces Using the tkinter Module
Control Circle Project Revisited
Chapter 12 Event-Driven Programming
Responding to Events Event Handling in Java
Chapter 1: An Introduction to Visual Basic 2015
Chapter 8: Writing Graphical User Interfaces
Java FX.
Creating Complex Animations
Graphical User Interface (pronounced "gooey")
Visual programming Chapter 1: Introduction
Java Programming: From Problem Analysis to Program Design,
Ellen Walker Hiram College
Chap 7. Building Java Graphical User Interfaces
Graphical User Interfaces -- Introduction
Event Driven Programming
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Recall: Timeline Class
Chapter 15 Event-Driven Programming and Animations
Hands-on Introduction to Visual Basic .NET
1/10/2019 JavaFX Events COSC 330.
Lecture 9 GUI and Event Driven CSE /16/2019.
Exception Handling and Event Handling
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
11.1 Applets & graphics.
Chapter 15 Event-Driven Programming and Animations Part 1
Chapter 15 Event-Driven Programming and Animations Part 2
Presentation transcript:

Chapter 15 Event-Driven Programming and Animations Dr. Clincy - Lecture

Recall: Basic Structure of JavaFX We have already examined the creating the GUI frontend and placing (or mapping) the nodes or buttons on the pane or scene Stage object is automatically created by JVM - window. Scene object is the container for the content – frame in the window. Node object (or button) is a visual component used to invoke some type of action Lets now explore making the nodes or buttons active – Event Driven Programming Panes can be used to help layout the nodes within a scene. Dr. Clincy - Lecture

Handling GUI Events Listener object contains a method for processing the event Source object (e.g., button, polygon, image, etc.) Event object (e.g., mouse click, mouse pointer over object, type characters into a textfield, etc ) Not all objects can be handlers for some action event. To be a handler of an event, there are two requirements: The object must be an instance of the interface called EventHandler. NOTE: the EventHandler interface defines the common behavior for all handlers The handler, which is the object generated from the EventHandler interface, MUST be “registered” with the event source object using the method source.setOnAction(handler) The full format for interface EventHandler is: EventHandler<T extends Event> where T is a generic type that extends the subtype Event. The EventHandler interface contains the handle(ActionEvent) method for processing action events. NOTE: Your handler class must override the handle(ActionEvent) method to respond to the event. Dr. Clincy - Lecture

Example: Event-Driven Programming Given the two buttons in the frame, when the OK button is clicked, the message, “OK button clicked” should be displayed to the console. When the Cancel button is clicked, the message “Cancel button clicked” should be displayed to the console. Dr. Clincy - Lecture

Example: Event-Driven Programming First, let’s create the handler classes for the OK and Cancel buttons Creating the OK handler class by implementing the EventHandler interface Overriding the EventHandler’s handle method Handling the event is simply printing the statement “OK button clicked” to the console Creating the Cancel handler class by implementing the EventHandler interface Handling the event is simply printing the statement “Cancel button clicked” to the console Now that we have created the handler classes for each button, let’s now use those classes in the Main Dr. Clincy - Lecture

Example: Event-Driven Programming Import the following for the events and handlers Creating and setting up pane Creating the OK button Creating the Cancel button Creating the OK button’s handler from the class created (recall the listener must be an instance of a listener interface) Registering the newly created handler with the OK button (recall a listener must be registered with a source object) Creating the Cancel button’s handler from the class created Registering the newly created handler with the Cancel button Mapping the OK and Cancel buttons to the pane Setting the stage Now the OK and Cancel buttons can “listen” for mouse click events as the program runs – and react accordingly. Dr. Clincy - Lecture

Event Classes Source object (e.g., button, polygon, image, etc.) Event object (e.g., mouse click, mouse pointer over object, type characters into a textfield, etc ) Listener object contains a method for processing the event Java’s root class for an event object is java.util.EventObject JavaFX’s root class for an event is javafx.event.Event There are three types of events Dr. Clincy - Lecture

Some Examples: Selected User Actions and Handlers Dr. Clincy - Lecture

Animation Class JavaFX provides the Animation class with the core functionality for all animations. Below are some of the core functionalities for JavaFX animations. A Boolean that answers will the animation reverse its direction on the next cycle Also, there are many concrete subclasses of the Animation class – your book covers the PathTransition, FadeTransition and Timeline classes. Dr. Clincy - Lecture

PathTransition Class The PathTransition class animates the moves of a node along a path from one end to the other over a given time The Duration class defines a duration time. Yon can use new Duration(double millis) to create an instance of Duration The add, subtract, multiple and divide methods are used to perform arithmetic operations You can use toHours(), toMinutes(), toSeconds() and toMillis() to return timein different measures You can use compareTo to compare two durations Dr. Clincy - Lecture

Example: PathTransition Write a program that animates a rectangle moving along a circle. Import the following for animation Creating a rectangle Creating a circle Adding the circle and rectangle to the pane Creating a PathTransition Setting the transition duration Setting the path of the transition Setting the node of the transition Setting the orientation of the node during the transition Setting the cycle count to indefinite Setting AutoReverse to be true Starting the animation Pausing the animation Resuming the animation Setting the stage Dr. Clincy - Lecture

FadeTransition Class The FadeTransition class animates the change of the opacity (transparency) in a node over a given time. Dr. Clincy - Lecture

Example: FadeTransition Write a program that applies a fade transition to a filled color in a ellipse. Import the following for animation Creating a ellipse Setting ellipse’s fill color Setting ellipse’s outline Binding the ellipse to the pane Add ellipse to pane Create FadeTransition Setting starting transparency level Setting ending transparency level Setting cycle count Setting AutoReverse to be true Starting the animation Pausing the animation Resuming the animation Setting the stage Dr. Clincy - Lecture

Timeline Class PathTransition and FadeTransition classes define specialized animations. The Timeline class can be used to program any animation using one or more KeyFrames. Each KeyFrame is executed sequentially at a specified time interval. Timeline inherits from Animation. Dr. Clincy - Lecture

Example: Timeline Class Write a program that flashes text on and off Import the following for animation and text Create a stack pane Create the text Add the text to the pane Create handler for changing text (this causes the on and off) Set text empty Set text Create a timeline Create a KeyFrame for handler Set cycle count indefinite Starting the animation Pausing the animation Resuming the animation Setting the stage Dr. Clincy - Lecture

Cover Project 2 Dr. Clincy - Lecture