Quiz on Event Listeners

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. An object that waits for and responds to an event from a GUI component is a:

a.    event listener
b.    GUI listener
c.    collection class
d.    click listener

Correct Answer Is:

2. What is an event object

a.    An event object represents one specific event, such as a mouse click.
b.    An event object is an object that listens for mouse clicks.
c.    An event object is a list of all the events that have happened in the system.
d.    An event object is what your program does in response to an event.

Correct Answer Is:

3. What two things must your program do to respond to a particular type of event?

a.    Set up an event generator, and set up an event listener.
b.    Create an event listener object for the type of event, and register it with the object that generates those events.
c.    Create a container for the events, and register it with the system.
d.    Create a Frame object and register it with the event listeners.

Correct Answer Is:

4. Fill in the blanks so that the following defines a listener that will respond to window closing events:

public class WindowQuitter extends _____________
  public void _____________( WindowEvent e )
    System.exit( 0 );  // what to do for this event

a.    JFrame, windowQuitting
b.    JFrame, windowFrame
c.    WindowAdapter, windowClosing
d.    WindowAdapter, windowSystem

Correct Answer Is:

5. What method of a JFrame object is used to register a window listener with it?

a.    addWindowListener()
b.    register()
c.    setListener()
d.    ignoreEvent()

Correct Answer Is:

6. How can the main() method which constructs a JFrame object be part of the definition of the JFrame that is constructs?

a.    This is not possible.
b.    This is a special exemption to the rules.
c.    Since main() is static, it doesn't really matter in what class it is defined.
d.    Every class has a main() method.

Correct Answer Is:

7. If there are several buttons in a frame, will each one generate its own events when the user clicks on it?

a.    Yes—each event is unique and is generated by a specific button.
b.    No—events are indistinguishable from each other.
c.    Yes—each button is allowed to generate one event. After that it is silent.
d.    No—only event listeners are unique.

Correct Answer Is:

8. Can a single listener object respond to several types of events from the same component?

a.    Yes—as long as it has an appropriate method for each type.
b.    No—there must be a specific listener object for each type of event from each component in a GUI.
c.    Yes—there is always only one listener in the entire program, so it has to respond to all types of events.
d.    No—a program can only respond to one type of event.

Correct Answer Is:

9. Must a program respond to all events that its components generate?

a.    Yes—the program that is running must handle all events that happen in anywhere one the screen or mouse.
b.    No—it can safely ignore events that don't concern it.
c.    Yes—if an event is generated that it can't handle it will bomb.
d.    No—the operating system sends the program only those events it can handle.

Correct Answer Is:

10. Which of the following generate events:

a.    Buttons
b.    Mouse movements.
c.    Scroll bar drags.
d.    All of the above and more.

Correct Answer Is:

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

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

Click here     Back to the main menu.