Questions and Exercises

 <  Day Day Up  >  

Use the information in this chapter and, if necessary, the component how-to sections in Chapter 7 to help you complete these exercises.

Questions

1:

Find the component that best fits each of the following needs. Write down both the component's common name (such as "frame") and the page its how-to discussion begins on (such as page 236). [ Hint: You can use the visual index, which begins on page 37, to help you answer this question. ]

  1. A component that lets the user pick a color .

  2. A component that displays an icon, but that doesn't react to user clicks.

  3. A component that looks like a button and that, when pressed, brings up a menu of items for the user to choose from.

  4. A container that looks like a frame, but that appears (usually with other, similar containers) within a real frame.

  5. A container that lets the user determine how two components share a limited amount of space.

2:

Which method do you use to add a menu bar to a top-level container such as a JFrame ?

3:

Which method do you use to specify the default button for a top-level container such as a JFrame or JDialog ?

4:

Which method do you use to enable and disable components such as JButton s? What class is it defined in?

5:
  1. Which Swing components use ListSelectionModel s? [31] [ Hint: The "Use" link at the top of the specification for each interface and class takes you to a page showing where in the API that interface or class is referenced. ]

    [31] ListSelectionModel API documentation: http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/ListSelectionModel.html.

  2. Do those components use any other models to handle other aspects of the components' state? If so, list the other models' types.

6:

Which type of model holds a text component's content?


Exercises

Use the information in this chapter and, if necessary, the component how-to sections in Chapter 7 to help you complete these exercises.

1:

Implement a program with a GUI that looks like the one shown in Question 1. Put the main method in a class named MyDemo1 .

2:

Make a copy of MyDemo1.java named MyDemo2.java . Add a menu bar to MyDemo2 . (The menu bar can be empty.)

3:

Copy MyDemo1.java to MyDemo3.java . Add a button ( JButton ) to MyDemo3.java . Make it the default button.


Answers

You can find answers to the Questions and Exercises online:

http://java.sun.com/docs/books/tutorial/uiswing/QandE/answers.html

 <  Day Day Up  >  


JFC Swing Tutorial, The. A Guide to Constructing GUIs
The JFC Swing Tutorial: A Guide to Constructing GUIs (2nd Edition)
ISBN: 0201914670
EAN: 2147483647
Year: 2004
Pages: 171

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net