Apply Your Knowledge

Review Questions

1:What is a layout manager?
2:What advantage do Java's layout managers provide over traditional windowing systems?
3:What are the problems faced by Java programmers who don't use layout managers?
4:What method is used to specify a container's layout?
5:How are the elements of a BorderLayout organized?
6:How are the elements of a CardLayout organized?
7:How are the elements of a FlowLayout organized?
8:How are the elements of a GridLayout organized?
9:How are the elements of a GridBagLayout organized?
10:Which containers use a BorderLayout as their default layout?
11:Which containers use a FlowLayout as their default layout?
12:What is the preferred size of a component?

Exam Questions

1:The following is an example of which layout?

  1. CardLayout

  2. null layout

  3. BorderLayout

  4. SetLayout

2:The following is an example of which layout?

  1. CardLayout

  2. null layout

  3. BorderLayout

  4. SetLayout

3:The following is an example of which layout?

  1. GridLayout

  2. FlowLayout

  3. GridLineLayout

  4. LineLayout

4:The following is an example of which layout?

  1. GridLayout

  2. null layout

  3. GridBagLayout

  4. GridBagConstraintLayout

5:The following is an example of which layout?

  1. GridLayout

  2. null layout

  3. GridBagLayout

  4. GridBagConstraintLayout

6:The following is an example of which layout?

  1. CardLayout

  2. null layout

  3. BorderLayout

  4. SetLayout

7:Given a component (comp) and a container (cont) that are organized according to a BorderLayout, which of the following should be used to add comp to the top of the container?
  1. addTop(cont,comp);

  2. comp.add("North",cont);

  3. cont.add("North",comp);

  4. cont.addTop(comp);

8:Given a component (comp) and a container (cont) that are organized according to a FlowLayout, which of the following should be used to add comp to the container?
  1. cont.add(comp);

  2. comp.add(cont);

  3. cont.addComponent(comp);

  4. cont.addAllComponents();

9:Which method is used to set the layout of a container?
  1. startLayout()

  2. initLayout()

  3. layoutContainer()

  4. setLayout()

10:Which method returns the preferred size of a component?
  1. getPreferredSize()

  2. getPreferred()

  3. getRequiredSize()

  4. getLayout()

11:Which method sets the size and position of a component?
  1. setBounds()

  2. setSizeAndPosition()

  3. setComponentSize()

  4. setComponent()

12:Which layout should you use to organize the components of a container in a tabular form?
  1. CardLayout

  2. BorderLayout

  3. FlowLayout

  4. GridLayout

Answers to Review Questions

A1: A layout manager is an object that is used to organize components in a container. See the section “Working with Layout Managers.”
A2: Java uses layout managers to lay out components in a consistent manner across all windowing platforms. Because Java's layout managers aren't tied to absolute sizing and positioning, they are able to accommodate platform-specific differences among windowing systems. See the section “Working with Layout Managers.”
A3: Without layout managers, Java programmers are faced with determining how their GUI will be displayed across multiple windowing systems and finding a common sizing and positioning that will work within the constraints imposed by each windowing system. See the section “Working with Layout Managers.”
A4: The setLayout() method is used to specify a container's layout. See the section “Using Layouts.”
A5: The elements of a BorderLayout are organized at the borders (North, South, East, and West) and the center of a container. See the section “The BorderLayout Class.”
A6: The elements of a CardLayout are stacked, one on top of the other, like a deck of cards. See the section “The CardLayout Class.”
A7: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. See the section “The FlowLayout Class.”
A8: The elements of a GridLayout are of equal size and are laid out using the squares of a grid. See the section “The GridLayout Class.”
A9: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different sizes and might occupy more than one row or column of the grid. In addition, the rows and columns might have different sizes. See the section “The GridBagLayout Class.”
A10: The Window, Frame, and Dialog classes use a BorderLayout as their default layout. See the section “The BorderLayout Class.”
A11: The Panel and Applet classes use the FlowLayout as their default layout. See the section “The FlowLayout Class.”
A12: The preferred size of a component is the minimum component size that will allow the component to display normally. See the section “AWT Components” in Chapter 11, “The java.awt Package: Components and Facilities,” and “Using Layouts” in this chapter.

Answers to Exam Questions

A1: C. See the section “Using Layouts.”
A2: A. See the section “Using Layouts.”
A3: B. See the section “Using Layouts.”
A4: A. See the section “Using Layouts.”
A5: C. See the section “Using Layouts.”
A6: B. See the section “Using Layouts.”
A7: C. The container's add() method is invoked, passing it the orientation and component as arguments. See the section “The BorderLayout Class.”
A8: A. The container's add() method is invoked, passing it the component as an argument. See the section “The FlowLayout Class.”
A9: D. setLayout() is used to set the layout of a container. See the section “Using Layouts.”
A10: A. getPreferredSize() returns the preferred size of a component. See the section “Using Layouts.”
A11: A. setBounds() sets the size and position of a component. See the section “Absolute Positioning.”
A12: D. The GridLayout is best if the table elements are of equal size. Otherwise, use a GridBagLayout. See the section “The GridLayout Class.”
Suggested Readings and Resources

1. The JDK 1.3 java.awt package API description. You can download this or browse it online at http://java.sun.com/j2se/1.3/docs.html.

2. Sun's tutorial at http://java.sun.com/docs/books/tutorial.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.96.247