CSE1720. Objectives for this class meeting 2/10/2014. Cover 2D Graphics topic: displaying images. Timer class, a basic ActionListener

Similar documents
CSE1720 Lecture 08; Week 05 Lecture 09 Second level Third level Fourth level Fifth level

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Event Driven Programming

Lecture 19 GUI Events

CSE 331 Software Design & Implementation

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CSE 331 Software Design and Implementation. Lecture 19 GUI Events

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Heavyweight with platform-specific widgets. AWT applications were limited to commonfunctionality that existed on all platforms.

IT101. Graphical User Interface

Module 4 Multi threaded Programming, Event Handling. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

MIT AITI Swing Event Model Lecture 17

Objectives for this class meeting. 1. Conduct review of core concepts concerning contracts and pre/post conditions

Class Meeting 04 (Lecture 03) Objectives for this class meeting

CS 251 Intermediate Programming GUIs: Event Listeners

CS 170 Java Programming 1. Week 15: Interfaces and Exceptions

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Topics. Transient vs Persistent Representation of Objects. Object Serialization CSE Lecture 9 Inheritance, III

CS 134 Programming Exercise 7:

CS 201 Advanced Object-Oriented Programming Lab 3, Asteroids Part 1 Due: February 17/18, 11:30 PM

UNIT-3 : MULTI THREADED PROGRAMMING, EVENT HANDLING. A Multithreaded program contains two or more parts that can run concurrently.

Programming Languages and Techniques (CIS120)

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Class 16: The Swing Event Model

CS211 GUI Dynamics. Announcements. Motivation/Overview. Example Revisted

The AWT Event Model 9

Cheng, CSE870. More Frameworks. Overview. Recap on OOP. Acknowledgements:

CS11 Java. Fall Lecture 4

CSE1720. General Info Continuation of Chapter 9 Read Chapter 10 for next week. Second level Third level Fourth level Fifth level

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

Java Event Handling -- 1

CS 160: Interactive Programming

Programming Languages and Techniques (CIS120)

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

This page intentionally left blank

Graphical User Interface (GUI)

Programming graphics

Programming Languages and Techniques (CIS120)

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Advanced Java Programming (17625) Event Handling. 20 Marks

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

CS 170 Java Programming 1. Week 9: Learning about Loops

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

CSci 1113, Fall 2018 Lab Exercise 11 (Week 13): Graphics. Warm-up

CSE 331. Event- driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Graphical User Interfaces 2

Computer Architecture and OS. EECS678 Lecture 2

UI Software Organization

Comp-361 : Game Programming Lecture 5

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

COMPSCI 230. Software Design and Construction. Swing

Mid-Semester Feedback

GUI Event Handlers (Part I)

CSE115 Lab 4 Fall 2016

G51PRG: Introduction to Programming Second semester Applets and graphics

Graphical User Interface (GUI)

CSE143 Notes for Monday, 7/06/15

CS250 Intro to CS II. Spring CS250 - Intro to CS II 1

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

CSE 331 Software Design & Implementation

AP CS Unit 11: Graphics and Events

Java Programming. Computer Science 112

UI Toolkits. HCID 520 User Interface Software & Technology

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

EECS1710. Announcements. epost updated, please check online Next Labtest: Thu Oct 23/Fri Oct 24. Next Term Test: Tue Oct 28.

Mobile MOUSe JAVA2 FOR PROGRAMMERS ONLINE COURSE OUTLINE

Event-driven Programming: GUIs

PIC 20A GUI with swing

the gamedesigninitiative at cornell university Lecture 12 Architecture Design

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Course: CMPT 101/104 E.100 Thursday, November 23, 2000

CSE Lecture 24 Review and Recap. High-Level Overview of the Course!! L1-7: I. Programming Basics!

CS11 Java. Fall Lecture 3

Developing Interactive Lectures with PowerPoint 2007

Composite Pattern Diagram. Explanation. JavaFX Subclass Hierarchy, cont. JavaFX: Node. JavaFX Layout Classes. Top-Level Containers 10/12/2018

Java Programming Lecture 7

Observer pattern. Somebody s watching me...

Programming of Graphics

Java Threads. Written by John Bell for CS 342, Spring 2018

Programming Mobile Devices J2SE GUI

Smoother Graphics Taking Control of Painting the Screen

Structured Programming

Anonymous Classes. A short-cut for defining classes when you want to create only one object of the class.

Assignment 1 What is a Computer?

Basic Input and Output

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

Basic Input and Output

CS371m - Mobile Computing. Responsiveness

CSE 131 Computer Science 1 Module 5: Modular Design

CSC207 Week 3. Larry Zhang

Graphical User Interfaces 2

Introduction to concurrency and GUIs

UI Toolkits. HCID 520 User Interface Software & Technology

Transcription:

CSE1720 Click to edit Master Week text 05, styles Lecture 09 Second level Third level Fourth level Fifth level Winter 2014! Tuesday, Feb 4, 2014 1 Objectives for this class meeting Cover 2D Graphics topic: displaying images Timer class, a basic ActionListener 2 1

Big picture recap via the services of the Picture class our app asks the window manager for a window the constructor creates and places a blank canvas inside this window this canvas has an associated Graphics2D object, which we can access via creategraphics() via the services of the Graphics2D class we use the services of this class to modify the current settings we use the services of this component to perform drawing of shape primitives and text 3 The VM and the window manager coordinate in order to do the drawing Shooter Games Shooting is a basic behaviour that is a defining characteristic of shooter games We will employ encapsulation: encapsulate the shooter encapsulate the projectile encapsulate the target Shooting entails: waiting for user input rendering the trajectory over a sequence of frames collision behaviours 4 2

Frame Drawing We need functionality to implement repeated frame drawing frames need to be drawn whether the user is performing actions or not we need a service that will dispatch events repeatedly, each of which signals draw new frame 5 Suspension of Disbelief Humans will suspend judgment about the implausibility of a narrative in order to engage with the material this alternative is that human does not suspend judgment, disengages and rejects premise of the material Video games require suspension of disbelief game mechanics are unrealistic (by design or by technological limitation) Designs seek to support suspension of disbelief and try to remove aspects that interfere with suspension of disbelief things that interfere: high frame rate, uncanny valley 6 3

Frame Rate The speed at which frames are drawn is called the frame rate TV: 60 fps Movies: 24 fps The Hobbit 3D experiment: 48 fps Lower threshold : 10-12 fps, phi phenomenon Upper threshold : ~66 fps A key concept: suspension of disbelief humans will suspend judgment about the implausibility of a narrative in certain conditions, but not others characteristics of the medium can trigger this 7 How we implement frames Dude, redraw the frame Hey Graphics2D here s what we re gonna do We will have two players here one that says when it is time to redraw the other says what happens to the screen when it is time to redraw 8 4

How we implement frames Dude, redraw the frame Hey Graphics2D here s what we re gonna do 9 What happens to the screen when it is time to redraw draw a red dot at the current point update the current point to a new position, moving along the diagonal this code can be found in Lab05 graphics.draw(dot); thecanvas.repaint(); p = new Point(p.x + 1, p.y + 1); dot = new Ellipse2D.Double(p.x, p.y, DIA, DIA); public class FrameAdvancer implements ActionListener { private Picture thecanvas; private Graphics2D graphics; private Point p; this code can be found in Lab05 private Shape dot; private final int DIA = 10; private long timeofinstantiation = System.currentTimeMillis(); public FrameAdvancer(Picture gamecanvas) { this.thecanvas = gamecanvas; p = new Point(0, 0); dot = new Ellipse2D.Double(p.x, p.y, DIA, DIA); graphics = thecanvas.creategraphics(); graphics.setpaint(color.red); } 10 } @Override public void actionperformed(actionevent ae) { graphics.draw(dot); thecanvas.repaint(); p = new Point(p.x + 1, p.y + 1); dot = new Ellipse2D.Double(p.x, p.y, DIA, DIA); } 5

How we implement frames Dude, redraw the frame Hey Graphics2D here s what we re gonna do We need functionality to implement repeated frame drawing we need to define the inter-frame interval (msec) we instantiate a Timer object this launches a new thread the thread fires events at the specified inter-frame interval 11 How we implement frames FrameAdvancer frameadvancer = new FrameAdvancer(pict); // change this value to indicate the desired number of frames per second final int NUM_FRAME_PER_SEC = 30; // here we determine how much time each frame should spend onscreen final int NUM_MSEC_PER_SEC = 1000; int msecperframe = NUM_MSEC_PER_SEC / NUM_FRAME_PER_SEC; Timer frameadvancertimer = new Timer(msecPerFrame, frameadvancer); frameadvancertimer.start(); this code can be found in Lab05 12 6

How to tune your radio 1. Identify the observee component this is the component that is dispatching events that you care about 2. Create an observer component this will be a component that is capable of listening to those types of events this is like tuning to the station 3. Use the services of the observee to tell it that it has an observer 13 The Observer Pattern Create an the observee component (the component that will be observed) this is the component that is dispatching events that you care about e.g., the Timer object dispatches ActionEvent events Create an observer component this will be a component that is capable of listening to those types of events e.g., the FrameAdvancer is an ActionListener 14 Use the services of the observee to tell it that it has an observer e.g., we provide the FrameAdvancer to the constructor of Timer 7

About Events in General Events are objects that encapsulate some sort of external happening the user did something e.g., performed a mouse or keyboard action the window manager did something e.g., opened a window, shifted focus 15 Java s Event Class Hierarchy EventObject A subset of Java s Event Class Hierarchy is shown here AWTEvent See Java API for full hierarchy ActionEvent ComponentEvent InputEvent WindowEvent MouseEvent KeyEvent 16 8

Back to the sample app Can you identify the observer and the observee? 17 Tasks slow down the projectile to have a slower trajectory" make the projectile expire before it reaches the edge of the screen" 18 9