graphics and java2d chapter 12. 2 java coordinate system origin is in _____________ corner –behind...

25
Graphics and Java2D Chapter 12

Upload: matthew-phillips

Post on 21-Jan-2016

216 views

Category:

Documents


0 download

TRANSCRIPT

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

Graphics and Java2D

Chapter 12

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

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 __________

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

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

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

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

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

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

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

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

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

7

Color Methods

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

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

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

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

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

10

Font Control Methods

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

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

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

12

Font Metrics Methods

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

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

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

14

Graphics Methods for Lines, Rectangles, Ovals

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

15

Graphics Methods for Lines, Rectangles, Ovals

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

16

Drawing Lines, Rectangles, Ovals

• Methods to manage:– Lines– Rectangles (_____________ or ____________)– Round cornered rectangles– 3D renditions of rectangles– Ovals

• Note height andwidth specs forovals

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

17

Drawing Lines, Rectangles, Ovals

• View sample program, Figure 12.14– Note use of ________________________() from Graphics class

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

18

Graphics Methods for Drawing Arcs

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

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

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

20

Graphics Methods for Drawing Polygons

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

21

Graphics Methods for Drawing Polygons

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

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

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

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;

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

24

Java2D API

• Note capabilities– New __________

added to shapesdrawn

– ____________– Fill with graphic– _____________ lines

• View Figure 12.22 which created this output

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

25

Java2D API

• General path : a shape constructed from– ___________ lines and– Complex ____________

• View Figure 12.23– Uses GeneralPath

package