Deck 16: Graphics
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Match between columns
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/66
Play
Full screen (f)
Deck 16: Graphics
1
The drawRoundRect() method requires ____ arguments.
A) three
B) four
C) six
D) eight
A) three
B) four
C) six
D) eight
C
2
You can instruct a Graphics object to use a font by inserting the font as the argument in a ____ method.
A) setColor()
B) drawString()
C) setCharacters()
D) setFont()
A) setColor()
B) drawString()
C) setCharacters()
D) setFont()
D
3
In Java, whether a paint request is triggered by the system or an application, a Component's paint() method is invoked.
True
4
The ____ method draws what appears to be an empty rectangle.
A) clearRect()
B) emptyRect()
C) fillRect()
D) drawRect()
A) clearRect()
B) emptyRect()
C) fillRect()
D) drawRect()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
5
The ____ method in the Graphics class allows you to draw a String on a JPanel or other component .
A) drawString()
B) setFont()
C) drawLine()
D) setString()
A) drawString()
B) setFont()
C) drawLine()
D) setString()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
6
The statements pen.drawLine(50, 50, 100, 200); and pen.drawLine(100, 200, 50, 50); will both draw straight lines that slant down and to the right.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
7
The drawPolygon() method requires four arguments, two integer arrays, and two single integers.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
8
System-triggered painting occurs when a program requests it, usually because the internal state of a component has changed.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
9
A rectangle created with the clearRect() method is not transparent.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
10
The getScreenSize() method returns an object of type Pixels , which specifies the width and height of the screen in pixels.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
11
The FontMetrics class methods return an integer value representing the font size in points, with one point measuring 1/72 of an inch.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
12
If you want to change graphic output on a panel in response to a user's mouse click, you would place a call to ____ in the actionPerformed() method.
A) paint()
B) paintComponent()
C) paintBorder()
D) repaint()
A) paint()
B) paintComponent()
C) paintBorder()
D) repaint()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
13
The first step in drawing a 2D object is to specify how a drawn object is rendered.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
14
When a Swing object such as JPanel calls the repaint() method, it calls paint(), paintComponent(), paintBorder() , and which of the following?
A) paintChildren()
B) paintSuper()
C) paintBody()
D) paintGraphic()
A) paintChildren()
B) paintSuper()
C) paintBody()
D) paintGraphic()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
15
The ____ method requires four arguments and draws the outline of a rectangle using the current drawing color.
A) clearRect()
B) drawRect()
C) fillRect()
D) paintRect()
A) clearRect()
B) drawRect()
C) fillRect()
D) paintRect()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
16
When using the drawRoundRect() method, if you assign ____ to the arc coordinates, the rectangle is not rounded; instead, the corners are square.
A) -1
B) 0
C) 10
D) 99
A) -1
B) 0
C) 10
D) 99
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
17
Both Rectangle2D.Float and Rectangle2D.Double can be created using four arguments representing the x-coordinate, y-coordinate, width, and height.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
18
You don't usually call the paint() method directly; instead the ____ method calls the paint() method.
A) destroy()
B) actionPerformed()
C) repaint()
D) super()
A) destroy()
B) actionPerformed()
C) repaint()
D) super()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
19
The lineTo() method is used to define the beginning point of a polygon.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
20
You can instruct a Graphics object named g to produce green output by using which of the following statements?
A) g.makeColor(Color.GREEN);
B) g.makeColor(GREEN.Color);
C) g.setColor(Color.GREEN);
D) g.setColor( GREEN. Color);
A) g.makeColor(Color.GREEN);
B) g.makeColor(GREEN.Color);
C) g.setColor(Color.GREEN);
D) g.setColor( GREEN. Color);
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
21
The ____ method provides information about the system in use.
A) getSystemInfo()
B) getDefaultToolkit()
C) getDefaultControlPanel()
D) getToolkit()
A) getSystemInfo()
B) getDefaultToolkit()
C) getDefaultControlPanel()
D) getToolkit()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
22
If the beginning and ending points used with the fillPolygon() method are ____, the two endpoints are connected by a straight line before the polygon is filled with color.
A) connected
B) coordinate pairs
C) identical
D) not identical
A) connected
B) coordinate pairs
C) identical
D) not identical
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following statements starts a polygon named pol at the coordinates 20 and 290?
A) pol.moveTo(20F, 290F);
B) pol.lineTo(20F, 290F);
C) pol = new Path(20F, 290F);
D) pol.newPath(20F, 290F);
A) pol.moveTo(20F, 290F);
B) pol.lineTo(20F, 290F);
C) pol = new Path(20F, 290F);
D) pol.newPath(20F, 290F);
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
24
You use the ____________________ method in statements to add points to a polygon.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
25
The ____________________ method can be used when a window needs to be updated, such as when it contains new images or you have moved a new object onto the screen.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
26
BasicStroke class variables determine the endcap and ____ style arguments.
A) stroke
B) line
C) juncture
D) fill
A) stroke
B) line
C) juncture
D) fill
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
27
You can discover the fonts that are available on your system by using the ____ method.
A) searchFonts()
B) findFonts()
C) findAllFonts()
D) getAvailableFontFamilyNames()
A) searchFonts()
B) findFonts()
C) findAllFonts()
D) getAvailableFontFamilyNames()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
28
The ____________________ method returns an object of type Dimension , which specifies the width and height of the screen in pixels.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
29
____ is the amount of space between the bottom of the descent of one line and the top of the characters in the successive line of type.
A) Descent
B) Ascent
C) Leading
D) Height of a line
A) Descent
B) Ascent
C) Leading
D) Height of a line
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
30
The ____ method creates a solid arc.
A) solidArc()
B) fillArc()
C) clearArc()
D) drawArc()
A) solidArc()
B) fillArc()
C) clearArc()
D) drawArc()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
31
The draw3DRect() method has a ____ argument, which controls whether the rectangle is darker on the right and bottom, or lighter on the right and bottom.
A) cyclic gradient
B) fill pattern
C) null
D) Boolean value
A) cyclic gradient
B) fill pattern
C) null
D) Boolean value
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
32
Which FontMetrics class method returns information about the part of characters that hang below the baseline?
A) getLeading()
B) getAscent()
C) get_Descent()
D) getHeight()
A) getLeading()
B) getAscent()
C) get_Descent()
D) getHeight()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
33
To create an arc object named halfArc that looks like the top half of a circle, which of the following statements can you use to produce identical results to this statement? halfArc.drawArc(x, y, w, h, 0, 180); .
A) halfArc.drawArc(x, y, w, h, 180, 0);
B) halfArc.drawArc(x, y, w, h, 180, -180);
C) halfArc.drawArc(x, y, w, h, -180, 180);
D) fillArc.drawArc(x, y, w, h, 180, -180);
A) halfArc.drawArc(x, y, w, h, 180, 0);
B) halfArc.drawArc(x, y, w, h, 180, -180);
C) halfArc.drawArc(x, y, w, h, -180, 180);
D) fillArc.drawArc(x, y, w, h, 180, -180);
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
34
Which of the following statements will correctly add a point to a polygon named myShape ?
A) myShape.addPoint(50, 100)
B) addPoint = myShape(50, 100)
C) myShape.fillPolygon(50 100)
D) myShape = addPoint(50, 100)
A) myShape.addPoint(50, 100)
B) addPoint = myShape(50, 100)
C) myShape.fillPolygon(50 100)
D) myShape = addPoint(50, 100)
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
35
You can use the ____ method to copy any rectangular area to a new location.
A) copyRect()
B) copyArea()
C) copyGraphics()
D) addPoint()
A) copyRect()
B) copyArea()
C) copyGraphics()
D) addPoint()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
36
You can improve the appearance of strings drawn using Graphics objects by using the ____________________ method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
37
You specify 2D colors by using the ____ method.
A) paint()
B) setPaint()
C) color()
D) setColor()
A) paint()
B) setPaint()
C) color()
D) setColor()
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
38
You can instantiate an empty Polygon object using which of the following statements?
A) Polygon someFutureShape = new Polygon(0,0,0,0);
B) Polygon someFutureShape = new Polygon();
C) Polygon someFutureShape = new Polygon(0);
D) Polygon someFutureShape = new Polygon(xPoints, yPoints, xPoints.length);
A) Polygon someFutureShape = new Polygon(0,0,0,0);
B) Polygon someFutureShape = new Polygon();
C) Polygon someFutureShape = new Polygon(0);
D) Polygon someFutureShape = new Polygon(xPoints, yPoints, xPoints.length);
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
39
You use the ____________________ method to draw a rectangle that appears to have "shadowing" on two of its edges and light "highlights" on two others.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
40
Which of the following is a gradual shift from one color at one coordinate point to a different color at a second coordinate point?
A) color shift
B) gradient fill
C) fill pattern
D) cyclic fill
A) color shift
B) gradient fill
C) fill pattern
D) cyclic fill
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
41
Match between columns
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
42
Write the statement to set the font of a Graphics object named myStyle to the font fancyFont .
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
43
What activities does the process of drawing with Java 2D objects include?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
44
Write the statement to create an Arc2D.Float object named myArc at 20, 143, with a width of 50 and a height of 43; with a starting degree of 50, 140 degrees traveled; and using the class variable Arc2D.PIE .
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
45
What parameters does the copyArea() method require?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
46
Describe what happens when a Swing component such as a JPanel calls the repaint() method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
47
BasicStroke myLine = new BasicStroke(12.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND);
The above statement creates a BasicStroke object and makes it the current stroke. Describe the three arguments that are used in this statement, and then describe the purpose of each.
The above statement creates a BasicStroke object and makes it the current stroke. Describe the three arguments that are used in this statement, and then describe the purpose of each.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
48
To create a rectangle with rounded corners, the drawRoundRect() method is used. Describe the six arguments that are required to create rounded rectangles.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
49
How can a programmer find and gather all the available fonts on a computer system?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
50
Write the statement that uses an object named brush to draw a string that says "I'm here" with the lower-left corner of the string appearing at coordinates x=100, y=110.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
51
How do you use the drawOval() method to draw an oval?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
52
The draw3DRect() method is used to draw rectangles that appear to have "shadowing" on two of their edges. Five arguments are used to create shadowed rectangles. Describe the five arguments.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
53
Write the statement to draw a rectangle using a graphics object named myRect that begins at position 30, 100 and is 150 pixels wide by 40 pixels tall.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
54
In the drawPolygon() method, what are the three arguments and what values do they represent?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
55
List the six arguments you need to provide for the drawArc() method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
56
A Polygon object is created by defining movements from one point to another. Describe the statements that are used to create a Polygon object.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
57
Write the statement that will create a BasicStroke object named myLine and make it the current stroke. The line width should be 3, the endcap style should be CAP_ROUND and the juncture style should be JOIN_BEVEL .
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
58
Why would a programmer use the repaint() method?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
59
What are the three arguments the BasicStroke constructor takes?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
60
What are the constructors for the Dimension class?
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
61
The getFontMetrics() method can be used to discover a font's statistics. Describe the getLeading() , getAscent() , getDescent() , and getHeight() methods, and how they are used with the getFontMetrics() method.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
62
Write the statement to create a Rectangle2D.Float object named myRect at 20, 20 with a width of 80 and height of 50.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
63
Write the setPaint() statement that will set a cyclic gradient that cycles between red and yellow that begins at coordinates 40, 60 and ends at coordinates 210, 120. The 2D graphics object you use in the statement should be named graph2D.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
64
import javax.swing.*;
import java.awt.*;
import java.awt.Color;
public class JDemo3DRectangles extends JPanel
{
@Override
public void paint(Graphics gr)
{
super.paint(gr);
final int WIDTH = 60, HEIGHT = 80;
gr.setColor(Color.PINK);
gr.fill3DRect(20, 40, WIDTH, HEIGHT, true);
gr.fill3DRect(100, 40, WIDTH, HEIGHT, false);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.add(new JDemo3DRectangles());;
frame.setSize(200, 180);
frame.setVisible(true);
}
}
The highlighted code above creates two filled 3D rectangles. Describe how the color of the rectangles is set, and explain the five arguments that are used to draw the rectangles.
import java.awt.*;
import java.awt.Color;
public class JDemo3DRectangles extends JPanel
{
@Override
public void paint(Graphics gr)
{
super.paint(gr);
final int WIDTH = 60, HEIGHT = 80;
gr.setColor(Color.PINK);
gr.fill3DRect(20, 40, WIDTH, HEIGHT, true);
gr.fill3DRect(100, 40, WIDTH, HEIGHT, false);
}
public static void main(String[] args)
{
JFrame frame = new JFrame();
frame.add(new JDemo3DRectangles());;
frame.setSize(200, 180);
frame.setVisible(true);
}
}
The highlighted code above creates two filled 3D rectangles. Describe how the color of the rectangles is set, and explain the five arguments that are used to draw the rectangles.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
65
A rectangle is drawn with the following statement:
tool.drawRect(50, 50, 100, 60);
An oval is drawn with the following statement:
tool.drawOval(50, 50, 100, 60);
Describe the resulting output, and describe how the four arguments are used to draw the objects.
tool.drawRect(50, 50, 100, 60);
An oval is drawn with the following statement:
tool.drawOval(50, 50, 100, 60);
Describe the resulting output, and describe how the four arguments are used to draw the objects.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck
66
Write the statement to instruct a Graphics object named myGraphic to apply blue paint.
Unlock Deck
Unlock for access to all 66 flashcards in this deck.
Unlock Deck
k this deck