|
|
控制板與佈局 |
佈局名 |
說明 |
FlowLayout |
預設佈局:若沒有指定則此為預設佈局 |
GridLayout |
設定柵格:所有元件都是相同大小 |
BorderLayout |
地圖佈局:選擇元件放在顯示區域的上、中、下、左、右 |
CardLayout |
元件堆疊:元件一個疊一個 |
GridBagLayout |
特殊複雜佈局 |
|
|
FlowLayout(預設佈局) |
import java.awt.*;
import java.applet.*;public class AppetWidthButton extends Applet
{ Button button1 = new Button("按我");
Button ok = new Button("確定");
Button cancel = new Button("取消");
Button apply = new Button("我高興");
Button options = new Button("我喜歡");
FlowLayout flowingButtons =
new FlowLayout(FlowLayout.RIGHT,10,15);
//用10個水平像素與15個垂直像素分隔元件,並靠右排列
public void init()
{
setLayout(flowingButtons);
add (button1);
add(ok);
add(cancel);
add(apply);
add(options);
}
} |
|
|
|
GridLayout(設定柵格) |
import java.awt.*;
import java.applet.*;public class AppetWidthButton extends Applet
{ Button button1 = new Button("按我");
Button ok = new Button("確定");
Button cancel = new Button("取消");
Button apply = new Button("我高興");
Button options = new Button("我喜歡");
GridLayout gridButtons = new
GridLayout(0,3,10,15);
//前兩個參數為設定這格中行列的數量,但只能二選一
public void init()
{
setLayout(gridButtons);
add (button1);
add(ok);
add(cancel);
add(apply);
add(options);
}
} |
|
|
|
BorderLayout(地圖佈局) |
import java.awt.*;
import java.applet.*; public class AppetWidthButton extends Applet
{ Button button1 = new Button("按我");
Button ok = new Button("確定");
Button cancel = new Button("取消");
Button apply = new Button("我高興");
Button options = new Button("我喜歡");
BorderLayout borderButtons = new BorderLayout(10,15);
public void init()
{
setLayout(borderButtons);
add ("North",button1);
add("East",ok);
add("West",cancel);
add("South",apply);
add("Center",options);
}
} |
|
|
|
本網頁由昱得資訊工作室製作(C)
Copyright Valor-Studio since in 1993
|
|
|