Java Reference
In-Depth Information
e) Font sizes are measured in units called .
f) Class helps specify the fill for a shape using a pattern drawn in a
BufferedImage
.
13.2
State whether each of the following is
true
or
false
. If
false
, explain why.
a) The first two arguments of
Graphics
method
drawOval
specify the center coordinate of
the oval.
b) In the Java coordinate system,
x
-coordinates increase from left to right and
y
-coordi-
nates from top to bottom.
c)
Graphics
method
fillPolygon
draws a filled polygon in the current color.
d)
Graphics
method
drawArc
allows negative angles.
e)
Graphics
method
getSize
returns the size of the current font in centimeters.
f) Pixel coordinate (0, 0) is located at the exact center of the monitor.
13.3
Find the error(s) in each of the following and explain how to correct them. Assume that
g
is a
Graphics
object.
a)
g.setFont(
"SansSerif")
;
b)
g.erase(x, y, w, h);
// clear rectangle at (x, y)
c)
Font f =
new
Font(
"Serif"
,
Font.BOLDITALIC
,
12
);
d)
g.setColor(
255
,
255
,
0
);
// change color to yellow
Answers to Self-Review Exercises
13.1
a)
setStroke
,
Graphics2D
. b)
GradientPaint
. c)
drawLine
. d) red, green, blue. e) points.
f)
TexturePaint
.
13.2
a)
False. The first two arguments specify the upper-left corner of the bounding rectangle.
b)
True.
c)
True.
d)
True.
e)
False. Font sizes are measured in points.
f)
False. The coordinate (0,0) corresponds to the upper-left corner of a GUI component
on which drawing occurs.
13.3
a) The
setFont
method takes a
Font
object as an argument—not a
String
.
b) The
Graphics
class does not have an
erase
method. The
clearRect
method should be
used.
c)
Font.BOLDITALIC
is not a valid font style. To get a bold italic font, use
Font.BOLD +
Font.ITALIC
.
d)
Method
setColor
takes a
Color
object as an argument, not three integers.
Exercises
13.4
Fill in the blanks in each of the following statements:
a)
Class
of the Java 2D API is used to draw ovals.
b)
Methods
draw
and
fill
of class
Graphics2D
require an object of type
as their
argument.
c)
The three constants that specify font style are
,
and
.
d)
Graphics2D
method
sets the painting color for Java 2D shapes.
13.5
State whether each of the following is
true
or
false
. If
false
, explain why.
a)
Graphics
method
drawPolygon
automatically connects the endpoints of the polygon.
b)
Graphics
method
drawLine
draws a line between two points.
c)
Graphics
method
fillArc
uses degrees to specify the angle.
d) In the Java coordinate system, values on the
y
-axis increase from left to right.
e)
Graphics
inherits directly from class
Object
.