Chapter 15 Event-Driven Programming and Animations

Slides:



Advertisements
Similar presentations
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Advertisements

Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 Chapter 12 More OOP, Interfaces, and Inner Classes.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Event Handling. In this class we will cover: Basics of event handling The AWT event hierarchy Semantic and low-level events in the AWT.
Event Handling Events and Listeners Timers and Animation.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 15 Event-Driven Programming.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
Event-Driven Programming
Inner Classes. Lecture Objectives Learn about inner classes. Know the differences between static and non- static inner classes. Designing and using inner.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 16 Event-Driven Programming.
1 Event-Driven Programming Just like designing GUIs, you also will probably not write Java code like the program examples given in these notes. You will.
10.1 AWT The AWT classes Users today expect a Graphical User Interface (GUI) Improves application usability Difficult to implement cross-platform.
CSE 331 Software Design & Implementation Dan Grossman Spring 2015 GUI Event-Driven Programming (Based on slides by Mike Ernst, Dan Grossman, David Notkin,
Java Programming: From Problem Analysis to Program Design, Second Edition1  Learn about basic GUI components.  Explore how the GUI components JFrame,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Event Driven Programming, The.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 14 Event-Driven Programming.
(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.
Omer Boyaci.  GUIs are event driven.  When the user interacts with a GUI component, the interaction—known as an event—drives the program to perform.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
Interactive Programs Java API. Terminology Event—an action or occurrence, not part of a program, detected by the program. Events can be Event—an action.
Lesson 6 Programming Techniques Event Handling /EvH/ AUBG ICoSCIS Team Assoc. Prof. Stoyan Bonev March, , 2013 SWU, Blagoevgrad.
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.
CS324e - Elements of Graphics and Visualization Timing Framework.
Java Programming: From Problem Analysis to Program Design, Second Edition1 Lecture 5 Objectives  Learn about basic GUI components.  Explore how the GUI.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Lecture 18: Events; Cool Applets Yoni Fridman 7/30/01 7/30/01.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2015 Pearson Education, Inc. All rights reserved. 1 Chapter 15 Event-Driven Programming and.
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
What Is an Event? Events – Objects that describe what happened Event sources – The generator of an event Event handlers – A method that receives an event.
CISC 110 Day 6 Introduction to Events. Outline Event-Driven Programming Event Classes Hierarchy –Event Class –Mouse Events –Keyboard Events Registering.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Object Oriented Programming in Java Habib Rostami Lecture 10.
UQC117S2 Graphics Programming Lecture 2 Event Handling Program as a sequence of instructions Event -driven program Need to detect the event and carry out.
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Jozef Goetz Credits: Copyright  Pearson Education, Inc. All rights reserved. expanded by J. Goetz, 2016.
Lecture 8:Event Driven Programming Michael Hsu CSULA.
Chapter 5: Enhancing Classes Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus.
GUI Programming using Java - Event Handling
Events and Event Handling
Chapter 14 Event-Driven Programming
CompSci 230 S Programming Techniques
Lecture 8:Event Driven Programming
Chapter 15 Event-Driven Programming and Animations
Control Circle Project Revisited
Chapter 12 Event-Driven Programming
Java Events. Java Events Important definitions Overridden method Class vs. abstract class vs. interface Event Handling Definition Main components Windows.
Processing Timer Events
CSE 331 Software Design & Implementation
CSE 331 Software Design & Implementation
Java Programming: From Problem Analysis to Program Design,
CSE 331 Software Design and Implementation
EE 422C Java FX.
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 15 Event-Driven Programming and Animations
Recall: Timeline Class
CSE 331 Software Design and Implementation
GUI Programming using Java - Mouse Events
CSE 331 Software Design and Implementation
Chapter 16 Event-Driven Programming
Events, Event Handlers, and Threads
Tonga Institute of Higher Education
Chapter 15 Event-Driven Programming and Animations Part 1
Chapter 15 Event-Driven Programming and Animations Part 2
CSE 331 Software Design & Implementation
Inner Classes.
ITEC220 GUI Lecture – Part 2 References
Presentation transcript:

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

Inner Class Listeners (RECALL) A listener class is designed specifically to create a listener object for a GUI component (e.g., a button). (RECALL) It will not be shared by other applications. (NEW) So, it is appropriate to define the listener class inside the frame class as an inner class. An Inner class is a member of another class. Advantages: In some applications, you can use an inner class to make programs simple and concise. An inner class can reference the data and methods defined in the outer class in which it nests, so you do not need to pass the reference of the outer class to the constructor of the inner class. Dr. Clincy - Lecture

Example - Inner Classes ( 1 ) This is a case of two separate classes ( 2 ) This is a case of Class A being an inner class to Class Test ( 3 ) This is another case of Class InnerClass being an inner class to Class OuterClass Dr. Clincy - Lecture

Recall: 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

Anonymous Inner Classes An Inner class listeners can be shortened using an anonymous inner classes. An anonymous inner class is an inner class without a name. It combines declaring an inner class and creating an instance of the class in one step. An anonymous inner class is declared as follows: new SuperClassName/InterfaceName() { // Implement or override methods in superclass or interface // Other methods if necessary } Original approach with two steps One step approach Dr. Clincy - Lecture

Simplifying Event Handing Using Lambda Expressions Lambda expression is a new feature in Java 8. Lambda expressions can be used to further simplify the code for event handling. Dr. Clincy - Lecture

The MouseEvent Class A MouseEvent is fired whenever a mouse button is pressed, released, clicked, moved or dragged on a node or a scene. Four constants are used, PRIMARY for left, SECONDARY for right, MIDDLE for middle and NONE for none. You can use the getButton () method to detect which button is pressed – getButton () == MouseButton.SECONDARY tests if right button was pressed. Dr. Clincy - Lecture

The KeyEvent Class A KeyEvent is fired whenever a keyis pressed, released or typed on a node or a scene. Dr. Clincy - Lecture

The KeyCode Constants Dr. Clincy - Lecture