DOC PREVIEW
LETU COSC 2103 - Chapter 12 - Graphics and Java 2D

This preview shows page 1-2-3-4-28-29-30-31-58-59-60-61 out of 61 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 61 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 12 - Graphics and Java 2D12.1 IntroductionFig. 12.1 Classes and interfaces used in this chapter from Java’s original graphics capabilities and from the Java2D API. [Note: Class Object appears here because it is the superclass of the Java class hierarchy.]Slide 4Fig. 12.2 Java coordinate system. Units are measured in pixels12.2 Graphics Contexts and Graphics Objects12.3 Color ControlFig. 12.3 Color constants and their RGB valuesFig. 12.4 Color methods and color-related Graphics methodsShowColors.java Line 18 Line 24 Line 25 Line 26ShowColors.java Lines 34-39ShowColors2.javaShowColors2.java Line 29 Line 29Slide 14Slide 15Fig. 12.7 HSB and RGB tabs of the JColorChooser dialog12.4 Font ControlFig. 12.8 Font-related methods and constantsSlide 19Fonts.java Line 24 Line 25Fonts.java Line 32 Line 37Slide 22Fig. 12.10 Font metricsFig. 12.11 FontMetrics and Graphics methods for obtaining font metricsMetrics.java Line 22 Line 23Metrics.java Lines 25-28 Lines 30-37Metrics.java12.5 Drawing Lines, Rectangles and OvalsFig. 12.13 Graphics methods that draw lines, rectangles and ovalsSlide 30LinesRectsOvals.javaLinesRectsOvals.java Line 30 Line 31 Line 34 Line 35 Line 38 Line 39Fig. 12.15 Arc width and arc height for rounded rectanglesFig. 12.16 Oval bounded by a rectangle12.6 Drawing ArcsFig. 12.17 Positive and negative arc anglesFig. 12.18 Graphics methods for drawing arcsDrawArcs.java Lines 24-26DrawArcs.java Lines 30-32 Lines 36-38 Line 41 Line 44 Line 47DrawArcs.java12.7 Drawing Polygons and PolylinesFig. 12.20 Graphics methods for drawing polygons and class Polygon methodsSlide 43DrawPolygons.java Lines 22-23 Line 26DrawPolygons.java Lines 28-29 Line 31 Lines 33-36 Line 39DrawPolygons.java12.8 Java2D APISlide 48Shapes.javaShapes.java Lines 27-28 Line 29 Lines 33-34 Lines 37-28 Lines 40-48Shapes.java Lines 51-52 Line 58 Line 62 Line 69Slide 52Shapes2.java Lines 24-25Shapes2.java Line 28 Lines 31-37 Lines 42-50Shapes2.java12.9 (Optional Case Study) Thinking About Objects: Designing Interfaces with the UMLFig. 12.24 Class diagram that models class Person realizing interface DoorListenerFig. 12.25 Elided class diagram that models class Person realizing interface DoorListenerPerson.java Lines 3-15Fig. 12.27 Class diagram that models realizations in the elevator modelFig. 12.28 Class diagram for listener interfaces 2003 Prentice Hall, Inc. All rights reserved.Outline12.1 Introduction12.2 Graphics Contexts and Graphics Objects12.3 Color Control12.4 Font Control12.5 Drawing Lines, Rectangles and Ovals12.6 Drawing Arcs12.7 Drawing Polygons and Polylines12.8 Java2D API12.9 (Optional Case Study) Thinking About Objects: Designing Interfaces with the UMLChapter 12 - Graphics and Java 2D 2003 Prentice Hall, Inc. All rights reserved.12.1 Introduction•Java’s graphics capabilities–Drawing 2D shapes–Controlling colors–Controlling fonts•Java 2D API–More sophisticated graphics capabilities•Drawing custom 2D shapes•Filling shapes with colors and patterns 2003 Prentice Hall, Inc. All rights reserved.Fig. 12.1 Classes and interfaces used in this chapter from Java’s original graphics capabilities and from the Java2D API. [Note: Class Object appears here because it is the superclass of the Java class hierarchy.]Classes and interfaces from the Java2D API that appear in package java.awtObjectColorComponentFontFontMetricsGraphicsPolygonGraphics2D interface java.awt.Paint interface java.awt.Shape interface java.awt.StrokeClasses from the Java2D API that appear in package java.awt.geomGradientPaintBasicStrokeTexturePaintRectangularShapeGeneralPathLine2DRoundRectangle2DArc2DEllipse2DRectangle2D 2003 Prentice Hall, Inc. All rights reserved.12.1 Introduction•Java’s coordinate system–Scheme for identifying all points on screen–Upper-left corner has coordinates (0,0)–Coordinate point composed of x-coordinate and y-coordinate 2003 Prentice Hall, Inc. All rights reserved.Fig. 12.2 Java coordinate system. Units are measured in pixelsX axisY axis(0, 0)(x, y)+x+y 2003 Prentice Hall, Inc. All rights reserved.12.2 Graphics Contexts and Graphics Objects•Graphics context–Enables drawing on screen–Graphics object manages graphics context•Controls how information is drawn–Class Graphics is abstract•Cannot be instantiated•Contributes to Java’s portability–Class Component method paint takes Graphics objectpublic void paint( Graphics g )–Called through method repaint 2003 Prentice Hall, Inc. All rights reserved.12.3 Color Control•Class Color–Defines methods and constants for manipulating colors–Colors are created from red, green and blue components•RGB values 2003 Prentice Hall, Inc. All rights reserved.Fig. 12.3 Color constants and their RGB valuesColor constant Color RGB value public final static Color ORANGE orange 255, 200, 0 public final static Color PINK pink 255, 175, 175 public final static Color CYAN cyan 0, 255, 255 public final static Color MAGENTA magenta 255, 0, 255 public final static Color YELLOW yellow 255, 255, 0 public final static Color BLACK black 0, 0, 0 public final static Color WHITE white 255, 255, 255 public final static Color GRAY gray 128, 128, 128 public final static Color LIGHT_GRAY light gray 192, 192, 192 public final static Color DARK_GRAY dark gray 64, 64, 64 public final static Color RED red 255, 0, 0 public final static Color GREEN green 0, 255, 0 public final static Color BLUE blue 0, 0, 255 2003 Prentice Hall, Inc. All rights reserved.Fig. 12.4 Color methods and color-related Graphics methodsMethod Description Color constructors and methods public Color( int r, int g, int b ) Creates a color based on red, green and blue components expressed as integers from 0 to 255. public Color( float r, float g, float b ) Creates a color based on red, green and blue components expressed as floating-point values from 0.0 to 1.0. public int getRed() Returns a value between 0 and 255 representing the red content. public int getGreen() Returns a value between 0 and 255 representing the green content. public int getBlue() Returns a value between 0 and 255 representing the blue content. Graphics methods for manipulating Colors public Color getColor() Returns a Color object representing the current color for the graphics context. public void setColor( Color c ) Sets the current color for drawing with the graphics context. 2003 Prentice Hall, Inc.All rights


View Full Document

LETU COSC 2103 - Chapter 12 - Graphics and Java 2D

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Chapter 12 - Graphics and Java 2D
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 12 - Graphics and Java 2D and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 12 - Graphics and Java 2D 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?