Quiz on JLabels and JTextFields

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. From what immediate base class is JTextField derived?

a.    JText
b.    JField
c.    JTextComponent
d.    JComponent

Correct Answer Is:


2. What goes in the blanks so that a text field of 20 characters is put into the frame?

  public TextExample()
  {  
    text = new JTextField( ____ ) ;
    getContentPane()._________( new FlowLayout() );
    getContentPane().add( ____ )
  }

a.    text, setLayout, 20
b.    20, setLayout, text
c.    20, put, frame
d.    20, set, text

Correct Answer Is:


3. What is the class of Swing labels?

a.    JLabel
b.    Label
c.    SLable
d.    label

Correct Answer Is:


4. How does FlowLayout() put components into the content frame?

a.    Starts at the top, then left to right in each row.
b.    Starts at the bottom, then right to left in each row.
c.    Starts at the center, then spirals outward.
d.    Puts the first component in the center, then squeezes the rest in around it.

Correct Answer Is:


5. When does a text field generate an action event?

a.    When the field has focus and the enter key is hit.
b.    For every character that is typed into the field.
c.    Whenever the frame has focus and the enter key is hit.
d.    When the text field looses focus.

Correct Answer Is:


6. When the user is typing into a text field may corrections be made?

a.    No, each character is sent to the application program as soon as it is typed.
b.    No, hitting backspace or delete terminates input.
c.    Yes, up until the enter key is hit.
d.    Yes, but only by deleting the entire line and starting over.

Correct Answer Is:


7. What method is used to read the text from a JTextField?

a.    readText()
b.    getText()
c.    getString()
d.    putText()

Correct Answer Is:


8. Can the program put text into a JTextField?

a.    No, only the user can enter text.
b.    Yes, by using a JLabel
c.    Yes, by using setEditable()
d.    Yes, by using a putText()

Correct Answer Is:


9. How can the user be prevented from entering text into a text field?

a.    By using setEditable( true )
b.    By using setEditable( false )
c.    By using setNotEditable()
d.    By using setVisible( false )

Correct Answer Is:


10. What method changes the color of a content pane?

a.    setColor()
b.    setBackgroundColor()
c.    setBackground()
d.    setForegroundColor()

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.)