Page 722 - Introduction to Programming with Java: A Problem Solving Approach
P. 722
688 Chapter 16 GUI Programming Basics
§16.7 JTextField Component
7. 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.
§16.9 Component Listeners
8. Write a statement that registers a listener reference variable named responder with a component named
component.
9. If you want a class to handle an event, what clause must be added to the right side of the class’s heading?
10. What is the heading of the one method specified by the ActionListener interface?
§16.10 Inner Classes
11. 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 .
§16.11 Anonymous Inner Classes
12. 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?
§16.12 JButton Component
13. In the createContents method of the FactorialButton program in Figure 16.8a, what type of object
calls the add methods?
14. In the FactorialButton program in Figures 16.8a and 16.8b, what component fires the event that the listener
handles?
Apago PDF Enhancer
§16.13 Dialog Boxes and the JOptionPane Class
15. What package contains the JOptionPane class?
16. 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.
§16.14 Distinguishing Between Multiple Events
17. 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?
§16.15 Using getActionCommand to Distinguish Between Multiple Events
18. 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.
§16.16 Color
19. Write a statement that sets the text color to blue for a JButton object named button1.
20. How do you get a reference to the container that surrounds all of the components in a JFrame object?
§16.17 How GUI Classes Are Grouped Together
21. If your program needs the java.awt.event subpackage, you can implicitly import it by importing the java.awt package. (T / F)