Jim Priest, Peter Lundgren, Russell Bennett. Background info  A sequence of fames  You have some experience already  Used for some GUI’s and Games.

Slides:



Advertisements
Similar presentations
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Advertisements

Made with love, by Zachary Langley Applets The Graphics Presentation.
Using Thread for Animation. Threads When we are doing multiple things at once we say we are multitasking Computers multitask when they run several programs.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
More Java Drawing in 2D Animations with Timer. Drawing Review A simple two-dimensional coordinate system exists for each graphics context or drawing surface.
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Albert Johnson Molly Richardson Andrew Kruth.  Threads Runnable interface sleep()  GUIs repaint() paintComponent()
G52CON: Concepts of Concurrency Lecture 2 Processes & Threads Chris Greenhalgh School of Computer Science
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
Advanced Java Class GUI – part 1. Intro to GUI GUI = Graphical User Interface -- “Gooey” Just because it’s “gooey” does not mean you may write messy code.
Enahnced Digital Clock Applet Setting applet parameters in the web page. The applet tag in HTML:
Building Memory… Day 3 – November 17, Two options to make Game graphical Game should extend some graphical component to allow us to put it on the.
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.
Applets. An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from a browser You.
Carnegie Mellon University, MISM1 Java GUI programming and Java Threads GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann Thread.
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
Lecture 18 Review the difference between abstract classes and interfaces The Cloneable interface Shallow and deep copies The ActionListener interface,
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Web Design & Development Lecture 18. Java Graphics.
Java: Animation Chris North cs3724: HCI. Animation? Changing graphics over time Examples: cartoons Clippy, agents/assistants Hour glass Save dohicky Progress.
Kirill Grouchnikov, Amdocs Desktop Matters Conference San Jose, March
CS12420 – Swing and threads Lynda Thomas
CSE 219 Computer Science III Images. HW1 Has been posted on Blackboard Making a Game of Life with limited options.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Object Oriented Programming Lecture 4: Refactoring, An Applet Example, Idiom - Animation applets, Introduction to the Laboratorial exercise www2.hh.se/staff/jebe/oop2005/
tiled Map Case Study: Rendering with JPanel © Allan C. Milne v
Chapter 12 Event Handling. Chapter Goals To understand the Java event model To install action and mouse event listeners To accept input from buttons,
Copyright © 2006 by The McGraw-Hill Companies, Inc. All rights reserved. McGraw-Hill Technology Education Game Programming Advanced Computer Programming.
J McQuillan SE204: 2004/2005: Lecture 4slide 1 The Graphics Class Used when we need to draw to the screen Two graphics classes –Graphics –Graphics2D.
Java Applets. An applet is a Panel that allows interaction with a Java program. A applet is typically embedded in a Web page and can be run from a browser.
Object Oriented Programming Lecture 5: Refactoring by Inheritance and Delegation - A simple Design Pattern for animation applets, A Generic Function Plotter.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Previous programs used a JLabel for OUTPUT. Another Swing component that can be used for both user input and output is the JTextfield. Suppose we want.
Review of CIS 120 Concepts: What you said you want….
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
User Interface Programming in C#: Direct Manipulation Chris North CS 3724: HCI.
Chapter 5: Ball Worlds Features 2 classes, constant data fields, constructors, extension through inheritance, graphics.
CSE 219 Computer Science III Image Manipulation. HW 1 Has been posted on Blackboard Making a Game of Life with limited.
Creating Your Own Widgets CompSci 230 S Software Construction.
Agenda Java Coordinate Systems. Graphics Class. Drawing on Panels. Drawing Shapes.
Java Direct Manipulation Chris North cs3724: HCI.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Java Programming Working with Sound and Images. Topics Learn about the paint() and repaint() methods Learn about paintComponent() method Use the drawString()
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
Graphics basic 1. 2 Objectives Understand Java coordinate systems. Draw things using the methods in the Graphics class. Override the paintComponent method.
Android Threads. Threads Android will show an “ANR” error if a View does not return from handling an event within 5 seconds Or, if some code running in.
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Java Dynamic Graphics.
17/3/00SEM107 © Kamin & Reddy Class 13 - Animation 1 Class 13 - Animation r Summary of loops m while-do m for m do-while r while loop examples r for loop.
Copyright © Curt Hill Applets A different type of program.
Object-Oriented Software Engineering Using Threads and simple Animation.
CHAPTER Agenda Applets Servelets Browsers HelloWorld.
Event Handling H_Func(Event) { } Event Receiver Object Source Object Registration.
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Java Graphics Chris North cs3724: HCI. Presentations peter hou Vote: UI Hall of Fame/Shame?
Java Applets Adding Animation. Import Files You still need to include the same files: –import java.applet.*; –import java.awt.*;
Getting Started with GUI Programming Chapter 10 CSCI 1302.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
Block 1 Unit 2 Basic Constructs in Java. Objectives create a simple object using a constructor; create and display a window frame on your computer screen;
GUI Programming in Java Hao Jiang Boston College April, 2009.
Creating Your Own Widgets
GUI AND GRAPHICS.
Movement (Paul Klee Signatures)
Project Snake. Project Snake Snake For this project, we’re going to make Snake This includes Making the overall game logic (using a 2D array) Handling.
Problem: Flickering Images
Presentation transcript:

Jim Priest, Peter Lundgren, Russell Bennett

Background info  A sequence of fames  You have some experience already  Used for some GUI’s and Games

Example /** * Draws the World and its Balls. * g the Graphics object onto which to draw. public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D graphics = (Graphics2D) g; this.drawWorld(graphics); this.drawBalls(graphics); } /** * Repeatedly repaints this panel. */ public void run() { while (true) { try { Thread.sleep(this.timeToSleep); this.repaint(); } catch (InterruptedException exception) { // If you can't sleep, no problem -- just continue. }

Important Concepts  Using threads to control animation behavior  Controlling the speed and smoothness using.sleep() Have a frame rate field. Pass 1000/frameRate to.sleep() Can’t have different frame rates for different animation objects on screen at same time After sleep, calls repaint.

Important Concepts  Using the run method Contains the animation thread Can be used to draw on the Frame  Using the paintComponent method Can be used to draw on the frame Still needs a thread to handle updating the frame

Important Concepts  “Flashing”  Overriding the update() method  Off-screen images “Double buffering”

Example class OptimizedDoubleBufferedCanvas extends Canvas { public void update(Graphics g) { Graphics offgc; Image offscreen = null; Rectangle box = g.getClipRect(); // create the offscreen buffer and associated Graphics offscreen = createImage(box.width, box.height); offgc = offscreen.getGraphics(); // clear the exposed area offgc.setColor(getBackground()); offgc.fillRect(0, 0, box.width, box.height); offgc.setColor(getForeground()); // do normal redraw offgc.translate(-box.x, -box.y); paint(offgc); // transfer offscreen to window g.drawImage(offscreen, box.x, box.y, this); }

Questions? Next, Demo