Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind...
-
Upload
matthew-phillips -
Category
Documents
-
view
216 -
download
0
Transcript of Graphics and Java2D Chapter 12. 2 Java Coordinate System Origin is in _____________ corner –Behind...
Graphics and Java2D
Chapter 12
2
Java Coordinate System
• Origin is in _____________ corner– Behind title bar of
window
• X values increase to the ________
• ________ increasedown the screen
• Coordinate units are in __________
3
Graphics Contexts & Objects
• A Java graphics enables drawing on the screen
• A Graphics object– Manages a graphics context– Draws pixels that represent ___________– Draws pixels that represent ___________
• Graphics objects have methods for – Drawing – Font and ___________ manipulation
4
The Graphics ClassThe 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
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 method
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
Color Methods
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
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
Font Control Methods
11
Font Control• Font class constructor arguments
– – –
• View demonstration of font control– Figure 12.9
• Note, to change the font– Must create a ________________________
–Font objects are ______________ – no set methods
12
Font Metrics Methods
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 metrics
14
Graphics Methods for Lines, Rectangles, Ovals
15
Graphics Methods for Lines, Rectangles, Ovals
16
Drawing Lines, Rectangles, Ovals
• Methods to manage:– Lines– Rectangles (_____________ or ____________)– Round cornered rectangles– 3D renditions of rectangles– Ovals
• Note height andwidth specs forovals
17
Drawing Lines, Rectangles, Ovals
• View sample program, Figure 12.14– Note use of ________________________() from Graphics class
18
Graphics Methods for Drawing Arcs
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 arcs
20
Graphics Methods for Drawing Polygons
21
Graphics Methods for Drawing Polygons
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 polylines
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
Java2D API
• Note capabilities– New __________
added to shapesdrawn
– ____________– Fill with graphic– _____________ lines
• View Figure 12.22 which created this output
25
Java2D API
• General path : a shape constructed from– ___________ lines and– Complex ____________
• View Figure 12.23– Uses GeneralPath
package