[Java] view plaincopy
/*
Time:
2012-10-18
Author:
Yang Zi
Program:
Display the frame Layout
*/
Import javax. swing .*;
Import java. awt .*;
Class Day1018_BoxLayout
{
Public static void main (String [] args)
{
JFrame f = new JFrame ("window ");
Container c = f. getContentPane (); // create a horizontal box
Box h1 = Box. createHorizontalBox (); // create a vertical Box
Box v1 = Box. createVerticalBox (); // create a vertical Box
Box v2 = Box. createVerticalBox (); // create a vertical Box
Box v3 = Box. createVerticalBox (); // create a vertical Box
For (int I = 0; I <10; I ++)
{
V1.add (new JButton ("G1 "));
V1.add (Box. createVerticalStrut (10); // Add the pillar to control the spacing of 10
}
H1.add (v1); // Add the vertical box to the horizontal box
For (int j = 0; j <10; j ++)
{
V2.add (new JButton ("G2 "));
V2.add (Box. createVerticalStrut (20); // Add the pillar with a distance of 20
}
H1.add (v2); // Add the vertical box to the horizontal box
For (int k = 0; k <10; k ++)
{
V3.add (new JButton ("G3 "));
V3.add (Box. createVerticalStrut (15); // Add the pillar to control the spacing of 15
}
H1.add (v3); // Add the vertical box to the horizontal box
C. add (h1 );
F. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE );
F. setVisible (true );
F. pack ();
}
}