Blakes 21 Days Chapter 11 Document


Day 11, Arranging Components on a User Interface

Basic Interface Layout

Laying Out an Interface

Flow Layout

First Program

Listing 11.1 The Full Text of Alphabet.java

The Explanation

Figure 11.1 - Six buttons arranged by a flow layout manager - goes here

Box Layout

Second Program

Listing 11.2 The Full Text of Stacker.java

The Explanation

Figure 11.2 - A user interface with buttons arranged with the box layout manager - goes here

Grid Layout

Third Program

Listing 11.3 The Full Text of Bunch.java

The Explanation

Figure 11.3 - Nine buttons arranged in a 3 x 3 grid layout - goes here

Border Layout

Figure 11.4 - Components arranged by a border layout manager - goes here

Fourth Program

Listing 11.4 The Full Text of Border.java

The Explanation

Mixing Layout Managers

Card Layout

Using Card Layout in an Application - Fifth Program

Figure 11.5 - Using a card layout for a wizard-style interface - goes here

Fifth Program

Listing 11.5 The Full Text of SurveyWizard.java

The Explanation

Sixth Program

Listing 11.6 The Full Text of SurveyFrame.java

The Explanation

Cell Padding and Insets



Summary



Q & A

Listing for Q&A The Text of Absolute.java



Quiz - Questions

  1. Whatis the default layout manager for a panel in Java ?
    1. None
    2. BorderLayout
    3. FlowLayout
  2. Which layout manager uses a compass direction or a reference to the center when adding a component to a container ?
    1. BorderLayout
    2. MapLayout
    3. FlowLayout
  3. If you want to create an installation wizard that has multiple steps, what layout manager should you use ?
    1. GridLayout
    2. CardLayout
    3. BorderLayout

Answers

  1. C. To keep a panel from using flow layout, you can set its layout manager to null.
  2. A. Border layout has class variables NORTH, EAST, WEST, and CENTER.
  3. B. Card layout enables components to be stacked like cards and displayed one at a time, making it well-suited to implement a wizard.


Certification Practice

  1. Which statement should replace // answer goes here to make the frame display all three buttons side by side ?
    1. content.setLayout(null);
    2. content.setLayout(new FlowLayout);
    3. content.setLayout(new GridLayout);
    4. content.setLayout(new BorderLayout);


Exercise