Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________.

Similar presentations


Presentation on theme: "Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________."— Presentation transcript:

1 Graphics and Java2D Chapter 12

2 2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________ ________ increase down the screen Coordinate units are in __________

3 3 Graphics Contexts & Objects A Java graphics enables drawing on the screen A Graphics object –Manages a graphics context –Draws pixels that represent ___________ Graphics objects have methods for –Drawing –Font and ___________ manipulation

4 4 The Graphics Class The paint() Method Graphics is an _____________ class –Cannot be instantiated Class Component has method ________ –Takes a ___________ object as an argument public void paint (Graphics g) Component also has –public void ___________() –public void update (Graphics g) We focus on the paint method in this chapter

5 5 The paint Method A Swing GUI needs to paint itself –The ___________ time –In response to becoming _____________ –Because it needs to reflect a change in the program's state Starts with the highest component that needs to be repainted –Works its way down the containment __________________. Sun tutorial on the paint methodSun tutorial

6 6 Color Control Class Color has – –Used to manipulate ______________ Colors created from mix of red, green, blue components –Specified in range from 0 to 255 (or floating point values 0.0 to 1.0) Methods include –Constructors, get (for R, G, B, and color), set

7 7 Color Methods

8 8 Color Control Note Figure 12.5 –Draws color __________ –Draws ___________ in color –Gets color values for use Note Figure 12.6 –Demonstrates the JColorChooser GUI component –Note the ___________ of the component for specifying the color in different ways

9 9 Graphics Applications As always the program "is a _________" This time –The class (program) extends _____________ –We have a constructor for the class –That ___________ does most of the activity The ___________ function does very little –Creates an instance of the class that is the program This instantiation calls the constructor –Sets up the exit call

10 10 Font Control Methods

11 11 Font Control Font class constructor arguments – View demonstration of font control –Figure 12.9Figure 12.9 Note, to change the font –Must create a ________________________ –Font objects are ______________ – no set methods

12 12 Font Metrics Methods

13 13 Font Metrics Sometimes necessary to get info about current drawing font –Name, style, font size –Class _________________ has methods for accessing Note further measurements (metrics) concerning fonts View Figure 12.12, program to manipulate font metricsFigure 12.12

14 14 Graphics Methods for Lines, Rectangles, Ovals

15 15 Graphics Methods for Lines, Rectangles, Ovals

16 16 Drawing Lines, Rectangles, Ovals Methods to manage: –Lines –Rectangles (_____________ or ____________) –Round cornered rectangles –3D renditions of rectangles –Ovals Note height and width specs for ovals

17 17 Drawing Lines, Rectangles, Ovals View sample program, Figure 12.14Figure 12.14 –Note use of ________________________() from Graphics class

18 18 Graphics Methods for Drawing Arcs

19 19 Drawing Arcs Definition of an arc –A portion of an ________ –Measured in _________ Arguments for arc methods –Coordinates for upper _____ corner –Height, width –________ for start of sweep –Number of degrees for ________ View Figure 12.19, drawing arcsFigure 12.19

20 20 Graphics Methods for Drawing Polygons

21 21 Graphics Methods for Drawing Polygons

22 22 Polygons and Polylines Polygon –Multisided shape –Composed of _________________ Polyline –Sequence of ______________ points Note Polygon class, pg 592 –Constructors View Figure 12.21, a program to draw polygons and polylinesFigure 12.21

23 23 Java2D API Advanced two-dimensional graphics Drawing accomplished with instance of Graphics2D –An abstract _____________ of Graphics –Must cast ____________________ passed to paint into a Graphics2D reference Graphics2D g2d = (Graphics2D) g;

24 24 Java2D API Note capabilities –New __________ added to shapes drawn –____________ –Fill with graphic –_____________ lines View Figure 12.22 which created this outputFigure 12.22

25 25 Java2D API General path : a shape constructed from –___________ lines and –Complex ____________ View Figure 12.23Figure 12.23 –Uses GeneralPath package


Download ppt "Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind title bar of window X values increase to the ________."

Similar presentations


Ads by Google