ptg7068951
196 HOUR 14: Laying Out a User Interface
Even though you haven’t added any statements that make the program do
anything yet, you can run the application to make sure that the graphical
interface is organized correctly and collects the information you need.
This application uses several different layout managers. To get a clearer
picture of how the application’s user interface is laid out, take a look at
Figure 14.7. The interface is divided into four horizontal rows that are sep-
arated by horizontal black lines in the figure. Each of these rows is a
JPanelobject, and the overall layout manager of the application organizes
these rows into a GridLayoutof four rows and one column.
1
2
3
4
FIGURE 14.7
Dividing the LottoMadness
application into panels.
Within the rows, different layout managers are used to determine how the
components should appear. Rows 1 and 3 use FlowLayoutobjects. Lines
45–46 of the program show how these are created:
FlowLayout layout1 = new FlowLayout(FlowLayout.CENTER,
10, 10);
Three arguments are used with the FlowLayout()constructor. The first
argument, FlowLayout.CENTER, indicates that the components should be
centered within their container—the horizontal JPanelon which they are
placed. The last two components specify the width and height that each
component should be moved away from other components. Using a width
of 10 pixels and a height of 10 pixels puts a small amount of extra distance
between the components.