Chapter Questions
What is a listener?
What is an event handler?
Write a statement that adds functionality to a program's close-window button such that when the closewindow button is clicked, it causes the program to terminate.
What is the name of the super class for classes that contain components?
What package are JButton and many other J-prefixed components defined in?
Provide an initialization statement that declares a JLabel reference variable named hello and assigns "Hello World" to the reference variable.
Provide an initialization statement that instantiates a 10 -character-wide text box object. As part of the initialization, assign the text box object to a reference variable named input.
Write a statement that registers a listener reference variable named responder with a component named component.
If you want a class to handle an event, what clause must be added to the right side of the class's heading?
What is the heading of the one method specified by the ActionListener interface?
If a class is limited in scope such that it is only needed internally within another class, you should define the class to be an ________.
If you want to implement an event handler with an anonymous inner class, what argument do you give to the addActionListener method to register the listener?
In the createContents method of the FactorialButton program in Figure $16.8 \mathrm{a}$, what type of object calls the add methods?
In the FactorialButton program in Figures $16.8 \mathrm{a}$ and $16.8 \mathrm{b}$, what component fires the event that the listener handles?
What package contains the JOptionPane class?
Write a statement that displays a dialog box in the center of the screen. The dialog box should display "This is only a test." in the message area, "TEST" in the title area, and no icon.
Suppose you have several components registered with the same listener, and the components and listener are defined within the same class. Within the listener, what ActionEvent method should you call to determine which component fires an event?
Assume there's a listener that's been registered for several different buttons. Assume the listener uses an actionPerformed method with an ActionEvent parameter named action. Assume that the user clicks one of the registered buttons. Provide a statement that retrieves the text label from the clicked button and assigns the retrieved label to a String variable named buttonLabel.
Write a statement that sets the text color to blue for a JButton object named button1.
How do you get a reference to the container that surrounds all of the components in a JFrame object?
If your program needs the java.awt.event subpackage, you can implicitly import it by importing the java.awt package. (T / F)