Java API 分類導覽 - java.awt.FlowLayout CENTER

FlowLayout 類別 (class) 的 CENTER 屬性 (field) 用作建構子 (constructor) 參數 (parameter) ,設定置中對齊。



修飾子
public static final int CENTER


舉例如下
import java.awt.*;
import java.awt.event.*;

public class FlowLayoutDemo {
    public static void main(String[] args) {
        Frame frame = new Frame("AWTDemo");
        frame.addWindowListener(new AdapterDemo());
        frame.setLayout(new GridLayout(5, 1));
        frame.setSize(420, 520);
        
        Panel p1 = new Panel(new FlowLayout(FlowLayout.CENTER));
        p1.setSize(400, 100);
        Button center = new Button("center");
        p1.add(center);
        Panel p2 = new Panel(new FlowLayout(FlowLayout.LEADING));
        p2.setSize(400, 100);
        Button leading = new Button("leading");
        p2.add(leading);
        Panel p3 = new Panel(new FlowLayout(FlowLayout.LEFT));
        p3.setSize(400, 100);
        Button left = new Button("left");
        p3.add(left);
        Panel p4 = new Panel(new FlowLayout(FlowLayout.RIGHT));
        p4.setSize(400, 100);
        Button right = new Button("right");
        p4.add(right);
        Panel p5 = new Panel(new FlowLayout(FlowLayout.TRAILING));
        p5.add(left);
        Button trailing = new Button("trailing");
        p5.add(trailing);
                
        frame.add(p1);
        frame.add(p2);
        frame.add(p3);
        frame.add(p4);
        frame.add(p5);
        
        frame.setVisible(true);
    }
}

class AdapterDemo extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
        System.exit(0);
    }
}

/* 《程式語言教學誌》的範例程式
    http://pydoing.blogspot.com/
    檔名:FlowLayoutDemo.java
    功能:示範 Java 程式 
    作者:張凱慶
    時間:西元 2012 年 3 月 */


此例建立五個 Panel 型態物件,依序設定為 FlowLayout 的置中對齊、依排列方式對齊、向左對齊、向右對齊、依最後一個元件對齊,然後每個 Panel 放入一個 Button
Panel p1 = new Panel(new FlowLayout(FlowLayout.CENTER));
p1.setSize(400, 100);
Button center = new Button("center");
p1.add(center);
Panel p2 = new Panel(new FlowLayout(FlowLayout.LEADING));
p2.setSize(400, 100);
Button leading = new Button("leading");
p2.add(leading);
Panel p3 = new Panel(new FlowLayout(FlowLayout.LEFT));
p3.setSize(400, 100);
Button left = new Button("left");
p3.add(left);
Panel p4 = new Panel(new FlowLayout(FlowLayout.RIGHT));
p4.setSize(400, 100);
Button right = new Button("right");
p4.add(right);
Panel p5 = new Panel(new FlowLayout(FlowLayout.TRAILING));
p5.add(left);
Button trailing = new Button("trailing");


編譯後執行,結果如下



中英文術語對照
類別class
屬性field
建構子constructor
參數parameter


您可以繼續參考
排版管理員


相關目錄
Java API 分類導覽
Java 教材
首頁


參考資料
http://docs.oracle.com/javase/6/docs/api/java/awt/FlowLayout.html

沒有留言: