站内搜索: 请输入搜索关键词
当前页面: 图书首页 > JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

Questions and Exercises - JFC Swing Tutorial, The: A Guide to Constructing GUIs, Second Edition

Previous Section  < Day Day Up >  Next Section

Questions and Exercises

Questions

In each of the following questions, choose the layout manager(s) most naturally suited for the described layout. Assume that the container controlled by the layout manager is a JPanel. [Hint: Two sections that might help are A Visual Index to Swing Components (page 37) in Chapter 3 and Choosing a Layout Manager (page 96) in this chapter.]

1:

The container has one component that should take up as much space as possible.

graphics/04inf01.gif

  1. BorderLayout

  2. GridLayout

  3. GridBagLayout

  4. a and b

  5. b and c

2:

The container has a row of components that should all be displayed at the same size, filling the container's entire area.

graphics/04inf02.gif

  1. FlowLayout

  2. GridLayout

  3. BoxLayout

  4. a and b

3:

The container displays a number of components in a column, with any extra space going between the first two components.

graphics/04inf03.gif

  1. FlowLayout

  2. BoxLayout

  3. GridLayout

  4. BorderLayout

4:

The container can display three completely different components at different times, depending perhaps on user input or program state. Even if the components' sizes differ, switching from one component to the next shouldn't change the amount of space devoted to the component.

graphics/04inf04.jpg

  1. SpringLayout

  2. BoxLayout

  3. CardLayout

  4. GridBagLayout


Exercises

1:

Implement the layout described and shown in question 1.

2:

Implement the layout described and shown in question 2.

3:

Implement the layout described and shown in question 3.

4:

Implement the layout described and shown in question 4.

5:

By adding a single line of code, make the program you wrote for Exercise 2 display the component from right-to-left, instead of from left-to-right.

graphics/04inf05.gif


Answers

You can find answers to the Questions and Exercises online:

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

    Previous Section  < Day Day Up >  Next Section