1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình đồ họa với AWT - Phần 5 pdf

13 323 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 13
Dung lượng 178,53 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Quảnlý ý trình h bày y  FlowLayout  Là layout mặc định cho Applet và Panel  Các thành phần được sắp xếp từ trái sang phải, trên xuống dưới  Các hàm khởi tạo  FlowLayout  Flow

Trang 1

Quảnlý ý trình h bày y

 Layout manager: quản lý cách trình bày của các GUI

components trong một Container

 Các layout manager

 FlowLayout

 BorderLayout

 CardLayout

 GridLayout

 GridBagLayout

 Sử dụng phương thức setLayout() của một Container để

thay đổi layout

Trang 2

Quảnlý ý trình h bày y

 FlowLayout

 Là layout mặc định cho Applet và Panel

 Các thành phần được sắp xếp từ trái sang phải, trên xuống dưới

 Các hàm khởi tạo

 FlowLayout()

 FlowLayout(int alignment)

Alignment có thể là FlowLayout.CENTER, LEFT, RIGHT

 FlowLayout(int, int, int)

Trang 3

Quảnlý ý trình h bày y

 FlowLayout

import java.awt.*;

import java.awt.event.*;

public class FlowLayoutTest extends Frame implements WindowListener {

public FlowLayoutTest(String title){

super(title);

addWindowListener(this);

setLayout(new FlowLayout(FlowLayout.CENTER, 20, 50));

for(int i = 1; i<15; i++)

add(new Button("Button"+i));

setSize(575, 300);

setVisible(true);

} public void windowClosing(WindowEvent e){

dispose();

System.exit(0);

Trang 4

Quảnlý ý trình h bày y

 FlowLayout

public void windowActivated(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public static void main(String[] args) { FlowLayoutTest ft = new FlowLayoutTest("FlowLayout Test");

} }

Trang 5

Quảnlý ý trình h bày y

 FlowLayout

Trang 6

Quảnlý ý trình h bày y

 BorderLayout

Để thêm một thành phần vào vùng ‘North’

Button b1=new Button(“North Button”); // khai báo thành phần

setLayout(new BorderLayout()); // thiết lập layout

add(b1,BorderLayout.NORTH); // thêm thành phần vào layout

 Khởi tạo: BorderLayout(), BorderLayout(int, int)

Trang 7

Quảnlý ý trình h bày y

 BorderLayout

Trang 8

Quảnlý ý trình h bày y

 CardLayout

 Tự tìm hiểu trong API Documentation

Trang 9

Quảnlý ý trình h bày y

 GridLayout

 Chia Container thành các ô lưới bằng nhau

 Các Component được đặt trong các ô

 Mỗi ô lưới nên chứa ít nhất một thành phần

 Ví dụ

GridLayout l1 = new GridLayout(4, 3)

,int)

Trang 10

Quảnlý ý trình h bày y

 GridLayout

import java.awt.*;

import java.awt.event.*;

public class GridLayoutTest extends Frame implements WindowListener {

public GridLayoutTest(String title){

super(title);

addWindowListener(this);

setLayout(new GridLayout(0, 3, 5, 10));

for(int i = 1; i<15; i++)

add(new Button("Button"+i));

pack();

setVisible(true);

}

Trang 11

Quảnlý ý trình h bày y

 GridLayout

public void windowClosing(WindowEvent e){

dispose();

System.exit(0);

}

public void windowActivated(WindowEvent e){}

public void windowClosed(WindowEvent e){}

public void windowIconified(WindowEvent e){}

public void windowDeiconified(WindowEvent e){}

public void windowDeactivated(WindowEvent e){}

public void windowOpened(WindowEvent e){}

public static void main(String[] args) {

GridLayoutTest ft = new GridLayoutTest(“GridLayout Test");

}

Trang 12

Quảnlý ý trình h bày y

 GridLayout

Trang 13

Quảnlý ý trình h bày y

 GridBagLayout

 Tự đọc

Ngày đăng: 14/08/2014, 22:21

TỪ KHÓA LIÊN QUAN

w