JAVA CORE - Trang 108

www.updatesofts.com


FlowLayout exLayout=new FlowLayout(FlowLayout.RIGHT);

setLayout(exLayout); //setting the layout to Flowlayout

Các điều khiển có thể được canh về bên trái, bên phải hay ở giữa. Để canh các điều khiển
về bên phải, bạn sử dụng cú pháp sau:

setLayout(new FlowLayout(FlowLayout.RIGHT));

Chương trình 5.9 minh họa về FlowLayout manager. Ở đây, contructor không cần được gọi
một cách tường minh, bởi vì cấu tử này được gọi mặc định cho một applet.

Chương trình 5.9


import java.awt.*;
class Fltest extends Frame
{

Button b1=new Button(“Center Aligned Button 1”);

Button b2=new Button(“Center Aligned Button 2”);

Button b3=new Button(“Center Aligned Button 3”);


public Fltest(String title)

{

super(title);

setLayout(new FlowLayout(FlowLayout.CENTER));

add(b1);

add(b2);

add(b3);

}

public static void main(String args[])

{

Fltest t=new Fltest(“Flow Layout”);

t.setSize(300,200);

t.show();

}

}

Kết xuất của chương trình chỉ ra ở hình 5.11.