Java Reference
In-Depth Information
8.
public class LayoutFrame extends SimpleFrame
9.
{
10.
public LayoutFrame(LayoutManager layout)
11.
{
12.
this. getContentPane().setLayout(layout);
13.
14.
ColorPanel CP1 = new ColorPanel(Color.red,30,30);
15.
ColorPanel CP2 = new ColorPanel(Color.yellow,40,20);
16.
ColorPanel CP3 = new ColorPanel(Color.green);
17.
ColorPanel CP4 = new ColorPanel(Color.blue);
18.
ColorPanel CP5 = new ColorPanel(Color.white,80,20);
19.
this .getContentPane().add(CP1);
20.
this .getContentPane().add(CP2);
21.
this .getContentPane().add(CP3);
this .getContentPane().add(CP4);
22.
this .getContentPane().add(CP5);
23.
}
24.
}
25.
File: its/Layouts/LayoutDriver.java
1.
package its.Layouts;
2.
3.
import java.awt.FlowLayout;
4.
import java.awt.GridLayout;
5.
6.
public class LayoutDriver
7.
{
8.
public static void main(String[] args)
9.
{
10.
FlowLayout flowLayout1 = new FlowLayout();
11.
LayoutFrame flow1Frame = new LayoutFrame(flowLayout1);
flow1Frame.showIt("Flow Layout 1",60,60);
12.
13.
14.
FlowLayout flowLayout2 = new FlowLayout(FlowLayout.LEFT,40,30);
LayoutFrame flow2Frame = new LayoutFrame(flowLayout2);
15.
flow2Frame.showIt("Flow Layout 2",300,60);
16.
17.
18.
GridLayout gridLayout = new GridLayout(2,4);
19.
LayoutFrame gridFrame = new LayoutFrame(gridLayout);
20.
gridFrame.showIt("Grid Layout",540,60);
21.
}
22.
}
Search WWH ::




Custom Search