Chapter 13: Graphics and Java 2D
Section 13.1 Introduction
13.1 Q1: In the Java coordinate system, the point (0, 0) is ________.
a. The lower-right corner of the screen.
b. The upper-right corner of the screen.
c. The lower-left corner of the screen.
d. The upper-left corner of the screen.
13.2 Q1: The fact that class Graphics is abstract contributes to Java’s portability
because ________.
a. drawing is performed differently on every platform that supports Java. A subclass of
Graphics must be created that uses the drawing capabilities of the current platform.
b. objects of non-abstract classes can only be instantiated on the Windows platform.
c. drawing should not be performed on non-Linux platforms.
d. Class Graphics is not abstract.
13.2 Q2: Which of the following statements about the Graphics object is true?
A. The Graphics object is an argument to class Component’s repaint method.
B. The Graphics object is instantiated by the user.
C. The Graphics object is the argument to a lightweight GUI component’s
paintComponent method.
D. The Graphics class is abstract.
E. The Graphics object manages a graphics context.
a. A, C, E.
b. C, D, E.
c. A, B, D, E.
d. All are true.
13.3 Q1: Which of the following are valid Java statements?
A. Color c = new Color(0, 255, 0);
B. Color c = new Color(0.0f, 1.0f, 0.0f);
C. Color c = new Color(0.0d, 1.0d, 0.0d);
D. setGreen(c.getGreen() 2);
a. All of the above.
b. A, B, C.
c. A, B, D.
d. A, B.
13.3 Q2: The JColorChooser dialog allows colors to be chosen by all but which of the
following?
a. Swatches.
b. Hue, saturation, brightness.
c. Gradient, cycle, brightness.
d. Red, Green, Blue.
13.4 Q1: Which of the following properly create and initialize a Font object?
A. Font f = new Font();
B. Font f = new Font(“Serif”, Font.Bold + Font.Italic, 19);
C. Font f = new Font(Font.Bold, 20, “SansSerif”);
D. Font f = new Font(20, Font.Bold, “Monospaced”);
a. A and B.
b. B and C.
c. B.
d. D.
13.4 Q2: Method getFont of class Graphics returns ________.
a. the current font name as a string
b. the font size in points
c. a Graphics object representing the current font
d. a Font object representing the current font
13.4 Q3: Which of the following is correct for font metrics?
a. height = descent + ascent + leading.
b. The amount the character dips below the baseline is the ascent.
c. The amount the character can be above the baseline is the leading.
d. The amount the character rises above the baseline is the descent.
13.4 Q4: Class FontMetrics declares methods that can be used to obtain the following
font metrics ________.
a. ascent, descent and height
b. ascent, descent and leading
c. height and leading
d. All of the above.
13.5 Q1: The Java statement:
g.fillOval(290, 100, 90, 55);
a. Draws a filled oval with its center at coordinates x=290, y=100, with height=90 and
width=55.
b. Draws a filled oval with its leftmost point at coordinates x=290, y=100, with height=90
and width=55.
c. Draws a filled oval bounded by a rectangle with its upper-left corner at coordinates
x=290, y=100, with width=90 and height=55.
d. Draws a filled oval bounded by a rectangle with its upper-left corner at coordinates
x=290, y=100, with height=90 and width=55.
13.5 Q2: The Java statement:
g.draw3DRect(290, 100, 90, 55, true);
a. draws a rectangle that appears to be raised (the top and left edges of the rectangle are
slightly darker than the rectangle).
b. draws a rectangle that appears to be lowered (the bottom and right edges of the
rectangle are slightly darker than the rectangle).
c. draws a rectangle that appears to be raised (the bottom and right edges of the rectangle
are slightly darker than the rectangle).
d. draws a rectangle that appears to be lowered (the top and left edges of the rectangle are
slightly darker than the rectangle).
13.6 Q1: Which of the following statements about arcs is false?
a. An arc is drawn as a part of an oval.
b. Arcs sweep from a starting angle the number of degrees specified by their arc angle.
c. Arcs that sweep clockwise are measured in positive degrees.
d. None of the above statements are false.
13.6 Q2: Which of the following statements draws an arc that sweeps from the top of an
oval to the leftmost edge?
a. g.drawArc(200, 100, 100, 50, 90, 90);
b. g.drawArc(100, 200, 50, 100, 90, 180);
c. g.drawArc(100, 200, 50, 100, 180, 90);
d. g.drawArc(200, 100, 100, 50, 180, 90);
13.7 Q1: Consider the code segment below:
int xValues[] = {100, 150, 200, 100};
int yValues[] = {30, 130, 30, 30};
g.drawPolyline(xValues, yValues, 4);
What kind of figure does it draw?
a. A rectangle.
b. A triangle.
c. A V with its corner at the top.
d. A square.
13.7 Q2: Consider the Java code segment below:
Polygon poly2 = new Polygon();
poly2.addPoint(100, 30);
poly2.addPoint(100, 130);
Which of the following will create a polygon that is a square?
a. poly2.addPoint(100, 60);
poly2.addPoint(100, 130);
b. poly2.addPoint(200, 130);
poly2.addPoint(200, 30);
c. poly2.addPoint(200, 60);
poly2.addPoint(200, 130);
d. poly2.addPoint(100, 130);
poly2.addPoint(100, 230);
13.8 Q1: Which of the following statements about the Java 2D API is true?
a. A Graphics2D object is instantiated to draw Java 2D figures.
b. Class Graphics2D is a subclass of class Graphics.
c. To access Graphics2D capabilities, cast the Graphics reference passed to
paintComponent to a Graphics2D reference.
d. All of the above are true.
13.8 Q2: The Graphics2D method(s) that determine(s) the color and texture for the shape
to display is/are:
a. setStroke
b. setPaint
c. setTexture and setColor
d. setTexturePaint
13.8 Q3: Which of the following statements is false?
a. A BufferedImage object uses the image stored in its associated TexturePaint object
as the fill texture for a filled-in shape.
b. Class BufferedImage can be used to produce images in color and gray scale.
c. Class GradientPath draws a shape in a gradually changing color.
d. All of the above are true.
13.8 Q4: A general path is ________.
a. a set of polylines that do not result in a closed shape
b. a shape constructed from straight lines and complex curves
c. the shape of the curve in a font’s characters
d. represented by an object of class GraphicsPath
13.8 Q5: GeneralPath method lineTo ________.
a. draws a line from the previous point in the GeneralPath object to the current point
b. draws a line with an arrow head to point to a GeneralPath object
c. moves the drawing origin around a line
d. specifies the first point in a GeneralPath object