Quiz on Swing Frames

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.

1. In Java, what do you call an area on the screen that has nice borders and various buttons along the top border?

a.    A window.
b.    A screen.
c.    A box.
d.    A frame.

Correct Answer Is:

2. What is the name of the Swing class that is used for frames?

a.    Window
b.    Frame
c.    JFrame
d.    SwingFrame

Correct Answer Is:

3. What method sets the size of the displayed JFrame?

a.    setSize( int width, int height)
b.    setSize( int height, int width)
c.    setVisible( int width, int height)
d.    setVisible( int height, int width)

Correct Answer Is:

4. The size of a frame on the screen is measured in:

a.    inches
b.    nits
c.    dots
d.    pixels

Correct Answer Is:

5. What is a container object in GUI programming?

a.    A container is another name for an array or vector.
b.    A container is any class that is made up of other classes.
c.    A container is a primitive variable that contains the actual data.
d.    A container is an object like a frame that has other GUI components placed inside of it.

Correct Answer Is:

6. Fill in the blanks so that this program displays a JFrame:

import java.awt.*;

public class microGUI
  public static void main ( String[] args )
    JFrame frm = new ___________();
    frm.___________( 150, 100 );
    frm.___________( true );

a.    Form, setVisible, setOn
b.    JFrame, setSize, setVisible
c.    Frame, setVisible, setSize
d.    Window, setSize, paint

Correct Answer Is:

7. Which of the following sets the frame to 300 pixels wide by 200 high?

a.    frm.setSize( 300, 200 );
b.    frm.setSize( 200, 300 );
c.    frm.paint( 300, 200 );
d.    frm.setVisible( 300, 200 );

Correct Answer Is:

8. Fill in the blanks so that the following draws a frame containing "Hello".

import java.awt.*; 

class helloFrame ___________ JFrame
  public void ___________( Graphics g )
    g.___________("Hello", 10, 50 );                                                 

public class Tester
  public static void main ( String[] args )
    helloFrame frm = new helloFrame();  
    frm.setSize( 150, 100 ); 
    frm.setVisible( true );

a.    import, drawString, paint
b.    extends, paint, drawString
c.    extends, draw, paint
d.    include, drawString, paint

Correct Answer Is:

9. When is the paint() method of a frame object called?

a.    The user calls it to display the frame.
b.    The main() method calls it once when the program starts.
c.    The Java system calls it every time it decides to display the frame.
d.    The Java system calls it once when the program starts.

Correct Answer Is:

10. What is a Graphics object?

a.    The Graphics object represents the part of the Frame that you can draw on.
b.    The Graphics object represents the whole Frame.
c.    The Graphics object represents the entire monitor.
d.    The Graphics object represents the graphics board.

Correct Answer Is:

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

Click here (If you have just returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the "shift key" while clicking on reload to clear the old answers.)