Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.

Slides:



Advertisements
Similar presentations
Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved. 1 Chapter 2 2D Graphics: Basics.
Advertisements

1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
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);
Draw Shapes Introduction to simple graphics. What is a graphics context? An instance of the Graphics class Graphics is ABSTRACT! You can extend Graphics.
Lecture07 Graphics Programming in Java. Introduction Most of the graphics programming of java is done with: Most of the graphics programming of java is.
Graphics Programming. In this class, we will cover: The difference between AWT and Swing Creating a frame Frame positioning Displaying information in.
1 Introduction to Applets Overview l What is an Applet? l Steps for creating an applet l What is HTML? l Basic HTML tags l Drawing Simple Graphical shapes.
1 L38 Graphics and Java 2D™ (3). 2 OBJECTIVES In this chapter you will learn:  To understand graphics contexts and graphics objects.  To understand.
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.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Swing Graphics ● Empty Swing containers have no visual appearance except for a background color ● Every JComponent must have a paintComponent method that.
Java Concepts Chapter 2 – Graphical Applications Mr. Smith AP Computer Science A.
Web Design & Development Lecture 18. Java Graphics.
CS324e - Elements of Graphics and Visualization Java2D Graphics.
Chapter 16: Graphics. Objectives Learn about the paint() and repaint() methods Use the drawString() method to draw String s using various fonts and colors.
1 Interface Types & Polymorphism & introduction to graphics programming in Java.
1 Graphical User Components (II) Outline JTextArea Creating a Customized Subclass of JPanel JPanel Subclass that Handles Its Own Events Windows: Additional.
(C) 2010 Pearson Education, Inc. All rights reserved. Omer Boyaci.
Chapter 15 Graphics and Java 2D™ Java How to Program, 8/e (C) 2010 Pearson Education, Inc. All rights reserved.
© 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.
 Pearson Education, Inc. All rights reserved. 1 Ch 12 Graphics and Java 2D In this chapter you will learn:  To understand graphics contexts.
Advanced User Interfaces with Java SD’98 - Session 3206 Ted Faison Faison Computing Inc.
Java Graphics Swing Graphics
2D Graphics Basics Chapter 2. Bird’s Eye View  Overview of Computer Graphics  2D Graphics: Basics –Basic 2D graphics, rendering pipeline, geometry,
Graphics and Java 2D. 2 Introduction Java’s graphics capabilities –Drawing 2D shapes –Controlling colors –Controlling fonts Java 2D API –More sophisticated.
Drawing and Filling Geometric Shapes. Java comes with more than just points and lines. Within the Graphics2D class, there are also methods for drawing.
 Definition: The ability to derive child classes (sub- classes) from parent classes (super-classes)  Characteristics:  Methods and instance variables.
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.
Graphics Copyright © 2015 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented Programming and Data.
Java Graphics. Review 3 kinds of elements in components API? Layout managers Events Extend vs. Implement.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. In order to display a drawing in a frame, define a class that extends.
Project 2: Thoughts Problems/Solutions Multiple Vectors vs. One Vector + easy to draw, - z order Shape can draw itself +separation.
1 Chapter 3 2D Graphics: Rendering Details  Color spaces, paints stroke types  Affine transforms including translation, rotation, scaling, shearing,
Creating Your Own Widgets CompSci 230 S Software Construction.
Georgia Institute of Technology Drawing in Java Barb Ericson Georgia Institute of Technology August 2005.
Introduction to Java Chapter 8 - Introduction to Java Graphics1 Chapter 8 Introduction to Java Graphics.
Java Dynamic Graphics.
Graphics and Java2D Chapter Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.
Georgia Institute of Technology Drawing in Java – part 3 Barb Ericson Georgia Institute of Technology September 2006.
Creating Vectors – Part One 2.02 Understand Digital Vector Graphics.
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 2D Drawing in Java 2. Agenda l Overview l Drawing Shapes l Paint Styles l Transparency l Using Local Fonts l Stroke Styles l Coordinate Transformations.
Advanced Java Screen Update Techniques SD’98 - Session 4406 Ted Faison Faison Computing Inc.
Georgia Institute of Technology Drawing in Java – part 2 Dr Usman Saeed Assistant Professor Faculty of Computing and Information Technology North Jeddah.
Main characteristics of Vector graphics  Vector graphics provide an elegant way of constructing digital images (diagrams, technical illustration and.
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.
10/20/2005week71 Graphics, mouse and mouse motion events, KeyEvent Agenda Classes in AWT for graphics Example java programs –Graphics –Mouse events –Mouse.
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.
Barb Ericson Georgia Institute of Technology September 2005
Advanced AWT The Rendering Pipeline
12 Graphics and Java 2D™.
Creating Your Own Widgets
Java 2D and SVG Rachel Struthers.
Java Graphics.
Java Graphics CS 2511.
JAVA 2 Design and programming of GUI
Java Graphics The basic rendering mechanism is the drawing system that controls when and how programs can draw on a graphics component. When a component.
2.02 Understand Digital Vector Graphics
12 Graphics and Java 2D™.
Chapter 49 Java 2D.
Creating Vectors – Part One
Handout-14 Applets and Graphics
Creating Vectors – Part One
Barb Ericson Georgia Institute of Technology September 2005
Presentation transcript:

Projects: not limited to spec Error checking File filters Create multiple file formats Polygons Filled shapes Etc.

Overview Graphics Project 2

Graphics Abstract class No instantiation Graphics g = someComponent.getGraphics()

Graphics API Graphics (1.1) Available fonts Lines drawn with a single-pixel width Shapes painted solid colors only

Java 1.1 Graphics public void paint(Graphics g) { // Set pen parameters g.setColor(someColor); g.setFont(someLimitedFont); // Draw a shape g.drawRect(...); // outline g.drawPolygon(...); // outline g.drawOval(...); // outline... } Example: Graphics 1.1

Graphics extended (1.2) Graphics2D Colors and patterns: gradient fills, fill patterns tiled images transparency Local fonts Pen thicknesses, dashing patterns, & segment connection styles Coordinate transformations Rotations & shearing

Java 2D: Common Methods public void drawString(String s, flt x, flt y) drawString(s, 2.0f, 3.0f) public void rotate(double theta) rotation of theta radians public void rotate(dbl theta, dbl x, dbl y) theta radians, point of rotation (x, y).

Continued public void scale(double xscale, yscale) Values greater than 1.0 expand the axis Values less than 1.0 shrink the axis public void setPaint(Paint paint) Solid Color, a GradientPaint, & TexturePaint public void setStroke(Stroke pen) Line thickness around object

Optional: modify drawing parameters g2d.setPaint(fillColorOrPattern); g2d.setStroke(penThicknessOrPattern); g2d.setComposite(someAlphaComposite); g2d.setFont(someFont); g2d.rotate(...); g2d.scale(...); g2d.setTransform(someAffineTransform);

Drawing a shape Call paintComponent method of superclass maintains the component look and feel clears off-screen pixmap (Swing implements double buffering) public void paint(Graphics){ super.paint(g); ….

Graphics 2D: Cast public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; …stuff here… }

Drawing Shape Objects public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D)g; // Assume x, y, and diameter are instance variables. Ellipse2D.Double circle = new Ellipse2D.double(x, y, diameter, diameter); g2d.fill(circle);... } There is double and float…idea being performance

Other shapes… Arc2D Ellipse2D GeneralPath, Line2D Rectangle2D, & RoundRectangle2D

Complex Constructors public Arc2D.Double( x, y, width, height, startAngle, deltaAngle, closure) A lot of built in functionality and methods ARC2D.OPEN ARC2D.PIE ARC2D.CHORD

Transforming shapes Using AffineTransforms AffineTransform at = new AffineTransform(); at.translate(150, 200); at.rotate(-Math.PI/3); at.scale(2, 0.5); g.transform(at); Ellipse2D.Float circle = new Ellipse2D.Float(-50, -50, 100, 100); g.draw(circle);

Transforming shapes AffineTransform at = new AffineTransform(); at.translate(150, 200); at.rotate(-Math.PI/3); at.scale(2, 0.5); Ellipse2D.Float circle = new Ellipse2D.Float(-50, -50, 100, 100); Shape shape = at.createTransformedShape(circle); g.draw(shape);

Resulting shape

General paths: Custom Shapes GeneralPath path = new GeneralPath(); path.moveTo(50, 50); path.lineTo(150, 150); path.quadTo(200, 200, 250, 150); path.curveTo(250, 250, 150, 250, 150, 200); path.closePath(); g.draw(path);

Creating…

Some Examples… Graphics Assortment of shapes Graphics 2D Added functionality Fonts Using fonts