May 13, 1998CS102-02Lecture 7-2 The End of Graphics in Java CS 102-02 Lecture 7-2 A picture's worth a thousand words.

Slides:



Advertisements
Similar presentations
Applets and Graphics.
Advertisements

Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Georgia Institute of Technology Drawing in Java – part 2 Barb Ericson Georgia Institute of Technology September 2005.
CSC1401 Drawing in Java - 2. Reminder from last class How do you save your modified picture? String filename = …; Picture stevePicture = new Picture(filename);
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Java Graphics Section 1 - Multi-File Graphics Programs Section 2 - The Coordinate System and Graphics Context g Section 3 - The Java Drawing and Painting.
GUI and Swing, part 2 The illustrated edition. Scroll bars As we have previously seen, a JTextArea has a fixed size, but the amount of text that can be.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
Copyright 2008 by Pearson Education Building Java Programs Graphics Reading: Supplement 3G.
1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details Graphics Objects.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Topics  Applets  Classes used for graphics Graphics Point Dimension.
May 11, 1998CS102-02Lecture 7-1 More Graphics in Java CS Lecture 7-1 A picture's worth a thousand words.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Java Graphics Applets.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 5 Applets and Graphics.
A Simple Applet. Applets and applications An applet is a Java program that runs on a web page –Applets can be run from: Internet Explorer Netscape Navigator.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
A Simple Applet.
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics F The architecture.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
Graphics. Graphics Features in Java Topics to be covered Topics to be covered Graphics Basics Graphics Basics Coordinate System Coordinate System Graphics,
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
Java Software Solutions Lewis and Loftus Chapter 7 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphics -- Introduction The.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction.
Chapter 28 - Java Graphics and Java2D Outline 28.1Introduction 28.2Graphics Contexts and Graphics Objects 28.3Color Control 28.4Font Control 28.5Drawing.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
2D Graphics Basics Chapter 2. Bird’s Eye View  Overview of Computer Graphics  2D Graphics: Basics –Basic 2D graphics, rendering pipeline, geometry,
Chapter 15Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 15 l Basic Figures l Colors l Fonts and Other Text Details.
Applets Applet is java program that can be embedded into HTML pages. Java applets runs on the java enabled web browsers such as mozilla and internet explorer.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
1 A Simple Applet. 2 Applets and applications An application is an “ordinary” program Examples: Notepad, MS Word, Firefox, Halo, etc. An applet is a Java.
-Sai Phalgun Tatavarthy. Outline What is a “Graphing Calculator”? Graphics, Graphics2D classes Methods of Graphics object Custom Painting The paintComponent()
Introduction to Java Simple Graphics. Objects and Methods Recall that a method is an action which can be performed by an object. –The action takes place.
Tkinter Canvas.
1 Building Java Programs Supplement 3G: Graphics These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They may not be rehosted, sold,
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Chapter 2: Graphics In Java Basics of classes –instance variables –methods –overriding methods Graphics class (drawing routines) Other classes –Color –Font.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Introductory Graphics Chapter Three. Computer Graphics §Full motion pictures (“Star Wars”) l animated films §Virtual reality §Games §Simulators (air craft.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Graphics Methods public abstract void drawString(String str, int x, int y): is.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
Getting Started with GUI Programming Chapter 10 CSCI 1302.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Graphics JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
CS202 Java Object Oriented Programming GUI Programming – Color and Drawing Methods Chengyu Sun California State University, Los Angeles.
Graphics Drawing Things With Java. Today's Topics Course Updates Java Graphics –Java 1.1 versus Java 1.2 (Java 2) Drawing Lines Drawing Shapes.
Graphics Applets By Mr. Dave Clausen
12 Graphics and Java 2D™.
Object Oriented Programming
Building Java Programs
Applets In Java Visit for more Learning Resources 1.
Building Java Programs
Graphics Applets By Mr. Dave Clausen
Java Applets.
Computer Graphics.
Building Java Programs
Graphics -- Introduction
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Graphics Reading: Supplement 3G
Presentation transcript:

May 13, 1998CS102-02Lecture 7-2 The End of Graphics in Java CS Lecture 7-2 A picture's worth a thousand words

May 13, 1998CS102-02Lecture 7-2 Agenda Arcs Revisited Polygons Messing with the Screen Paint modes Java2D

May 13, 1998CS102-02Lecture 7-2 Arc de Triomphe drawArc takes six arguments: –The rectangle: int x, int y, int width, int height Center of the arc is the center of the rectangle whose origin is (x, y) and whose size is specified by the width and height arguments –The angle at which to begin drawing the arc: int startAngle –The size of the arc to draw in degrees: int arcAngle

May 13, 1998CS102-02Lecture 7-2 The Arc and The Rectangle (x, y) heightheight width - 60° 120° arcAngle startAngle

May 13, 1998CS102-02Lecture 7-2 "Polly want a cracker?" "No, polygon!" Polygon is just a set of vertices –Array of points {(x1, y1), (x2, y2)... (xn, yn)} Polygonal methods draw lines and closed figures –Specify either a polygon object, or –A set of points

May 13, 1998CS102-02Lecture 7-2 Draw Your Own Polygon Two versions of drawPolygon drawPolygon(int xPoints[], int yPoints[], int points) drawPolygon(Polygon p) Polygons are always closed (the book is wrong) points <= array length –A logic error?

May 13, 1998CS102-02Lecture 7-2 Inside a Polygon Java draws and connects points in the order they're listed Sometimes you get interior points

May 13, 1998CS102-02Lecture 7-2 Building Polygon Objects Polygon class public Polygon(int xpoints[], int ypoints[], int npoints) –Constructs and initializes a polygon from the specified parameters

May 13, 1998CS102-02Lecture 7-2 Fill a Polygon Filled polygons are just like regular polygons, but painted in the foreground color fillPolygon(int xPoints[], int yPoints[], int points) fillPolygon(Polygon p)

May 13, 1998CS102-02Lecture 7-2 Feeling Disconnected? Draw a Polyline Polylines are just like polygons, except –If first and last point are different, they aren't automatically connected drawPolyline(int xPoints[], int yPoints[], int nPoints)

May 13, 1998CS102-02Lecture 7-2 Messin' with the Screen Copy one portion of a screen to another with copyArea() copyArea() needs to know two things –Area you want to copy (a rectangle) –How far to move the copy ( dX and dY ) relative to the origin of the rectangular area

May 13, 1998CS102-02Lecture 7-2 Start With This... 30,

May 13, 1998CS102-02Lecture 7-2 Use copyArea() copyArea(30, 10, 150, 150, 200, 60) Rectangle to copy from Move over dX, dY

May 13, 1998CS102-02Lecture 7-2 And Copy To This 30, , 10+60

May 13, 1998CS102-02Lecture 7-2 Painting a la Mode Pick a paint mode: overwrite or XOR Default as though setPaintMode() were called –When drawing, replace any color with current foreground color Can also setXORMode(Color xorColor)

May 13, 1998CS102-02Lecture 7-2 Paint and XOR Mode

May 13, 1998CS102-02Lecture 7-2 How XOR Mode Works Drawing in XORMode with XORColor –Pixels in the current color are changed to the specified color –And vice versa. Colors other than those two colors are changed in an unpredictable but reversible manner –If the same figure is drawn twice, then all pixels are restored to their original values

May 13, 1998CS102-02Lecture 7-2 The Code for the Picture public void paint(Graphics g) { // Draw in PaintMode g.setColor(Color.blue); g.fillPolygon(xPoints, yPoints, 4); g.setColor(Color.red); g.fillOval(20, 80, 200, 100); // Switch to XORMode with yellow g.setXORMode(Color.yellow); g.setColor(Color.blue); g.fillPolygon(xRightPoints, yPoints, 4); g.setColor(Color.red); g.fillOval(220, 80, 200, 100); }

May 13, 1998CS102-02Lecture 7-2 Overlapping Over and Over g.setColor(Color.red); // Now you see it g.fillOval(220, 80, 200, 100); //... now you don't g.fillOval(220, 80, 200, 100); //... now you see it again g.fillOval(220, 80, 200, 100); Book's explanation is a little simplistic

May 13, 1998CS102-02Lecture 7-2 Java2D Set of classes for advanced 2D graphics and imaging –Good for CAD/CAM –Games Included in JDK 1.2 (currently in beta 3) Built in to java.awt.* –Inheritance in action

May 13, 1998CS102-02Lecture 7-2 What's in Java2D? Line art, text, and images in a single comprehensive model Support for image compositing and alpha channel images Classes to provide accurate color space definition and conversion Rich set of display-oriented imaging operators