created: 01/22/00; revised: 10/04/03, 02/12/06, 07/02/16

Quiz on Drawing

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. To grade the quiz, click on the button at the bottom.

1. Where is the point (0, 0) located on a JPanel ?

A.    upper left corner
B.    upper right corner
C.    middle of the bottom edge
D.    center of the panel

2. What must be imported to get most graphics components?

A.    java.Graphics
B.    java.awt.* and java.swing.*
C.    java.util.* and java.math.*
D.    java.util.*

3. To draw a rectangle filled with the current color use this method:

A.    drawRect()
B.    fillrect()
C.    fillRect()
D.    fillRectangle()

4. What is the meaning of final in a declaration: final int width = 350;

A.    width is a loop control variable that will finally reach 350.
B.    width gets the value 350 and cannot be changed.
C.    width is the last variable in the list of variables.
D.    width shadows a similar instance variable.

5. If you are using the Graphics object gr and wish to change the pen color to red, what should you do?

A.    gr.setColor( Color.RED )
B.    gr.setPen( Color.RED )
C.    setBackground( Color.RED )
D.    gr.setRed( )

6. In what order must the vertices be added to a Polygon object?

A.    In clockwise order, starting with the left-most vertex.
B.    In either clockwise or counter clockwise order, going around the polygon, starting with any vertex.
C.    In any order, as long as all vertices are included.
D.    In clockwise order going around the polygon, starting with the top vertex.

7. What method call is used to draw a line from X=20, Y=30 to X=70, Y=50

A.    gr.drawLine( 20, 70, 30, 50 );
B.    gr.drawLine( (20, 30), (70, 50) );
C.    gr.drawLine( 20, 30, 50, 70 );
D.    gr.drawLine( 20, 30, 70, 50 );

8. What method of JPanel is called when the system needs to redraw the panel?

A.    paint()
B.    draw()
C.    paintPanel()
D.    paintComponent()

9. Say that a JPanel was originally made to be width pixels across, but now the user has changed the display so the panel is a new size. Which of the following should be used to multiply the X coordinates in the new drawing?

A.    double scale = ((double)getWidth())/width;
B.    double scale = width/getWidth();
C.    double scale = ((double)width)/getWidth();
D.    int scale = width/getWidth();

10. Your program has a reference to a Polygon object in the variable poly. How do you put an additional point in the list of vertices for that polygon?

A.    poly.point(x, y)
B.    poly.add(x, y)
C.    poly.addPoint(y, x)
D.    poly.addPoint(x, y)

The number you got right:       Percent Correct:       Letter Grade:   

Click here