Page 724 - Introduction to Programming with Java: A Problem Solving Approach
P. 724
690 Chapter 16 GUI Programming Basics {
BigHello hello = new BigHello();
} // end main
} // end BigHello class
To figure out how to do this, in Java’s API, look up the setFont, setBorder, and setToolTipText methods that JLabel inherits from JContainer. For the setFont argument, use JContainer’s getFont to get the default font, and then alter it by using Font’s two-parameter deriveFont method in which the first parameter specifies an italic font style and the second parameter specifies a 30-point size. Use JContainer’s setBorder method, and for its Border argument use the appropriate class method from the BorderFactory class.
5. [after §16.7] The width parameter in the JTextField constructor specifies the width of the text box in pixels. (T / F)
6. [after §16.7] What can you do to prevent users from updating a JTextField component?
7. [after §16.9] Write the heading for the method you must define in a class that implements an
ActionListener.
8. [after §16.9] The ActionListener interface and the ActionEvent class are in what Java API package?
9. [after §16.9] An interface is a class-like thing whose methods are all empty. If an interface is applied to a class, then the interface acts like a template that the class must conform to. (T / F)
10. [after §16.10] An inner class can directly access its enclosing class’s instance variables. (T / F) Apago PDF Enhancer
11. [after §16.12] It’s appropriate to use an anonymous inner class if you are going to use the class only once. In the Factorial program in Figures 16.8a and 16.8b, we use the listener object twice, so that listener object needed to have a name. However, we used that object’s class only once, to instantiate that one object. Therefore, that object’s class did not need to have a name, and we could have used an anonymous class
to create our listener object. For this exercise, modify the Factorial program to use an anonymous ActionListener class instead of the named Listener class. [Hint: The program is already set up to facilitate this change—it’s mostly cut-and-paste.]
12. [after §16.13] Do you have to create a JFrame window to use a JOptionPane dialog box?
13. [after §16.13] To answer this question, you may need to look up JOptionPane’s showInputDialog
and showConfirmDialog methods on Sun’s Java API Web site. What does this program do? import javax.swing.JOptionPane;
public class UncertainHello
{
public static void main(String[] args)
{
String name;
int response;
do
{
name = JOptionPane.showInputDialog("What's your name? ");
response = JOptionPane.showConfirmDialog(null, "Are you sure?");
if (response == JOptionPane.NO_OPTION)
{
name = "there";