SỬ DỤNG LAYOUT MANAGER TRONG THIẾT KẾ GIAO DIỆN

34 841 1
SỬ DỤNG LAYOUT MANAGER TRONG THIẾT KẾ GIAO DIỆN

Đ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

SỬ DỤNG LAYOUT MANAGER TRONG THIẾT KẾ GIAO DIỆN

SỬ DỤNG LAYOUT MANAGER TRONG THIẾT KẾ GIAO DIỆN Nhóm 3 NỘI DUNG Giới thiệu Chức năng của các Layout Demo I. GIỚI THIỆU 1. Layout manager là gì? a. Layout: Cách bố trí các thành phần trên container, hay nói cách khác là cách sắp xếp các thành phần vào các vị trí đặc biệt trong container. Việc này được quản lý bởi LayoutManager. b. LayoutManager: Sắp xếp vị trí của các components một cách tự động, thay vì xác định chính xác về vị trí và kích thước của các components trong container. Nếu chúng ta không sử dụng LayoutManger thì các component cũng được sắp xếp theo LayoutManager mặc định. I. GIỚI THIỆU 1. Layout manager là gì? c. Những hạn chế khi không sử dụng layout: Chúng ta cũng có thể sắp xếp các component bằng tay, tuy nhiên nó gặp nhiều rắc rối: .Khó khăn trong việc xử lý nhiều component. .Thường thì thông tin chiều rộng và chiều cao của component không được đưa ra khi sắp xếp chúng. I. GIỚI THIỆU 2. Phân loại các Layout manager Các loại LayoutManager hổ trợ trong java bao gồm: .BorderLayout .FlowLayout .BoxLayout .CardLayout .GridLayout .GridBagLayout .GroupLayout .SpringLayout II. CÁC LOẠI LAYOUT MANAGER 1. BorderLayout a. Giới thiệu II. CÁC LOẠI LAYOUT MANAGER 1. BorderLayout a. Đặc điểm: a. . Sắp xếp các thành phần(component) vào 5 khu vực: East, West, North, South và Center. Mỗi khu vực chỉ có thể chứa một thành phần và mỗi thành phần trong từng khu vực được xác định bởi các hằng số tương ứng: NORTH, SOUTH, EAST, WEST và CENTER. Nếu chỉ có container chỉ chứa một component thì nó sẽ phủ kín container đó. . Là layout manager mặc định của Jframe. Cú pháp khai báo: public class BorderLayout extends Object implements LayoutManager2, Serializable II. CÁC LOẠI LAYOUT MANAGER 1. BorderLayout c. Hàm khởi tạo public BorderLayout public BorderLayout(int hgap, int vgap) e. Một số phương thức hay sử dụng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER 1. BorderLayout d. Một số phương thức hay sử dụng public void setHgap(int hgap) public void setVgap(int vgap) public Object getConstraints(Component comp) public float getLayoutAlignmentX(Container parent) public float getLayoutAlignmentY(Container parent) public Component getLayoutComponent(Container target, Object constraints) public Component getLayoutComponent(Object constraints) Tham khảo thêm tại nguồn: http ://docs.oracle.com/javase/7/docs/api/java/awt/BorderLayout.html II. CÁC LOẠI LAYOUT MANAGER 2. a. a. FlowLayout Đặc điểm: . Sắp xếp các components trên cùng một dòng từ góc trên bên trái đến góc dưới bên phải của màn hình, khi nào hết chỗ chứa nó sẽ tự động xuống dòng, ta cũng có thể điều chỉnh hướng xuất hiện của components. . Mặc định khi một JPanel được khởi tạo thì bản thân lớp chứa này sẽ có kiểu Layout là FlowLayout Cú pháp khai báo public class FlowLayout extends Object implements LayoutManager, Serializable II. CÁC LOẠI LAYOUT MANAGER FlowLayout 2. c. Hàm khởi tạo public FlowLayout() public FlowLayout(int align) public FlowLayout(int align, int hgap, int vgap) e. Một số phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) II. CÁC LOẠI LAYOUT MANAGER FlowLayout 2. d. Một số phương thức thường dùng public int getAlignment public void setAlignment() public void setHgap(int hgap)  public void setVgap(int vgap) public void getHgap()  II. CÁC LOẠI LAYOUT MANAGER FlowLayout 2. d. Một số phương thức thường dùng public void getVgap() public void setAlignOnBaseline(Boolean alignOnBaseline)  public bolean getAlignOnBaseline()  public void removeLayoutComponent(Component comp)  Tham khảo thêm tại nguồn: http:// docs.oracle.com/javase/7/docs/api/java/awt/FlowLayout.html II. CÁC LOẠI LAYOUT MANAGER BoxLayout 3. a. Đặc điểm: Cho phép đặt nhiều components theo các dòng và các cột liên tiếp nhau. Trong BoxLayout thường dùng Jpanel để hiển thị và nó có thể chứa nhiều Jpanel khác nhau. b. Cú pháp khai báo public class BoxLayout extends Object implements LayoutManager LayoutManager2, Serializable II. CÁC LOẠI LAYOUT MANAGER BoxLayout 3. c. Hàm khởi tạo public BoxLayout(Container target, int axis) e. Một số phương thức thường dùng public final Container getTarget() public final int getAxis() public void invalidateLayout(Container target) II. CÁC LOẠI LAYOUT MANAGER BoxLayout 3. d. Một số phương thức thường dùng public void addLayoutComponent(String name, Component comp) public void removeLayoutComponent(Component comp) public void addLayoutComponent(Component comp, Object constraints) public Demention preferredLayoutSize(Container target) public Demention minimumLayoutSize(Container target) II. CÁC LOẠI LAYOUT MANAGER CardLayout 4. a. Đặc điểm: Cho phép bố trí các components thành từng lớp như các quân bài trong một bộ bài. Để chứa các components ta thường sử dụng các Jpanel. Tại một thời điểm chỉ có một Jpanel được hiển thị. b. Cú pháp khai báo public class CardLayout extends Object implements LayoutManager2, Serializable II. CÁC LOẠI LAYOUT MANAGER CardLayout 4. c. Hàm khởi tạo public CardLayout() public CardLayout(int hgap, int vgap) e. Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER 4. d. CardLayout Các phương thức thường dùng public void setHgap(int hgap) public void setVgap(int vgap) public void first(Component parent) public float getLayoutAlignmentX(Container parent) public float getLayoutAlignmentY(Container parent) public void layoutContainer(Container parent) Tham khảo thêm tại nguồn: http:// docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html  II. CÁC LOẠI LAYOUT MANAGER GridLayout 5. a. Đặc điểm: Bố trí các components dưới dạng lưới, với các dòng và các cột đều nhau, mỗi một khung lưới chỉ chứa một components duy nhất. b. Cú pháp khai báo public class GridLayout extends Object implements LayoutManager, Serializable II. CÁC LOẠI LAYOUT MANAGER GridLayout 5. c. Hàm khởi tạo public GridLayout() public GridLayout(int rows, int cols) public GridLayout(int rows, int cols, int hgap, int vgap) e. Các phương thức thường dùng public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER 5. d. GridLayout Các phương thức thường dùng public void setHgap(int hgap) public void setVgap(int vgap) public int getColumns () public int getRows() public void setColumns(int cols) Public void setRows(int rows) public void layoutContainer(Container parent) Tham khảo thêm tại: http:// docs.oracle.com/javase/7/docs/api/java/awt/GridLayout.html  II. CÁC LOẠI LAYOUT MANAGER 6. a. GridBagLayout Đặc điểm: Cho phép đặt một component trên một số ô kề nhau theo cả hay chiều. Nó hiệu quả nhưng phức tạp hơn các layout khác. Các component trong GridBagLayout không cần có cùng kích thước. . Tương tự như GridLayout nhưng thứ tự đặt các component không theo nguyên tắc sắp xếp thì trái qua phải và từ trên xuống dưới, bạn cần cung cấp thông tin về kích thước và vị trí của mỗi thành phần. . a. Cú pháp khai báo public class GridBagLayout extends Object implements LayoutManager2, Serializable II. CÁC LOẠI LAYOUT MANAGER GridBagLayout 6. c. Hàm khởi tạo public GridBagLayout() e. Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER GridBagLayout 6. d. Các phương thức thường dùng protected void adjustForGravity(GridBagConstraints constraints, Rectangle r) protected void AdjustForGravity(GridBagConstraints constraints, Rectangle r) protected void arrangeGrid(Container parent) protected void ArrangeGrid(Container parent) II. CÁC LOẠI LAYOUT MANAGER GridBagLayout 6. d. Các phương thức thường dùng public GridBagConstraints getConstraints(Component comp) public Point location(int x, int y) public void invalidateLayout(Container target) Tham khảo thêm tại nguồn: http:// docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.htm l   II. CÁC LOẠI LAYOUT MANAGER Group layout 7. a. Đặc điểm: . Thực hiện với chiều ngang và dọc riêng biệt. Sự sắp xếp được định nghĩa độc lập với nhau, không cần phải quan tâm về kích thước theo chiều dọc khi xác định bố trí nằm ngang và ngược lại. . Sử dụng hai loại sắp xếp – tuần tự và song song, kết hợp với thành phần thứ bậc. . Thêm khoảng cách giữa các component một cách tự động, những khoảng cách này được tính toán dựa trên look-and-feel thực sự. II. CÁC LOẠI LAYOUT MANAGER Group layout 7. a. Đặc điểm: . Tất cả các thành phần được lưu giữ kích thước mặc định của nó. . Không này. b. có sub-panel được sử dụng để xây dựng trong trường hợp Cú pháp khai báo public class GroupLayout extends Object implements LayoutManager2 II. CÁC LOẠI LAYOUT MANAGER Group layout 7. c. Hàm khởi tạo public GroupLayout(Container host) e. Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER Group layout 7. d. Các phương thức thường dùng protected void adjustForGrivaty(GridBagConstraints constraints, Rectangle r) public GroupLayout.ParallelGroup createBaselineGroup(boolean resizeable, boolean anchorBaselineToTop) public GroupLayout.ParallelGroup createParallelGroup() public GroupLayout.ParallelGroup createParallelGroup( GroupLayout.Alignment alignment) II. CÁC LOẠI LAYOUT MANAGER Group layout 7. d. Các phương thức thường dùng public GroupLayout.ParallelGroup createParallelGroup( GroupLayout.Alignment alignment, boolean resizeable) public GroupLayout.SequentialGroup createSequentialGroup() public boolean getAutoCreateGaps() Tham khảo thêm tại nguồn: http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.ht ml   II. CÁC LOẠI LAYOUT MANAGER Spring layout 8. a. Đặc điểm: .Các components được đặt lên có liên quan với nhau. .… b. Cú pháp khai báo public class SpringLayout extends Object implements LayoutManager2 II. CÁC LOẠI LAYOUT MANAGER Spring layout 8. c. Hàm khởi tạo public SpringLayout() e. Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II. CÁC LOẠI LAYOUT MANAGER Spring layout 8. d. Các phương thức thường dùng [...]... LAYOUT MANAGER CardLayout 4 a Đặc điểm: Cho phép bố trí các components thành từng lớp như các quân bài trong một bộ bài Để chứa các components ta thường sử dụng các Jpanel Tại một thời điểm chỉ có một Jpanel được hiển thị b Cú pháp khai báo public class CardLayout extends Object implements LayoutManager2, Serializable II CÁC LOẠI LAYOUT MANAGER CardLayout 4 c Hàm khởi tạo public CardLayout() public CardLayout(int hgap,... docs.oracle.com/javase/7/docs/api/java/awt/CardLayout.html  II CÁC LOẠI LAYOUT MANAGER GridLayout 5 a Đặc điểm: Bố trí các components dưới dạng lưới, với các dòng và các cột đều nhau, mỗi một khung lưới chỉ chứa một components duy nhất b Cú pháp khai báo public class GridLayout extends Object implements LayoutManager, Serializable II CÁC LOẠI LAYOUT MANAGER GridLayout 5 c Hàm khởi tạo public GridLayout() public GridLayout(int rows,... pháp khai báo public class GridBagLayout extends Object implements LayoutManager2, Serializable II CÁC LOẠI LAYOUT MANAGER GridBagLayout 6 c Hàm khởi tạo public GridBagLayout() e Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II CÁC LOẠI LAYOUT MANAGER GridBagLayout 6 d Các phương thức thường... Cú pháp khai báo public class GroupLayout extends Object implements LayoutManager2 II CÁC LOẠI LAYOUT MANAGER Group layout 7 c Hàm khởi tạo public GroupLayout(Container host) e Các phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) public void addLayoutComponent(String name, Component comp)  II CÁC LOẠI LAYOUT MANAGER Group layout 7 d Các phương thức thường dùng... Cho phép đặt nhiều components theo các dòng và các cột liên tiếp nhau Trong BoxLayout thường dùng Jpanel để hiển thị và nó có thể chứa nhiều Jpanel khác nhau b Cú pháp khai báo public class BoxLayout extends Object implements LayoutManager LayoutManager2, Serializable II CÁC LOẠI LAYOUT MANAGER BoxLayout 3 c Hàm khởi tạo public BoxLayout(Container target, int axis) e Một số phương thức thường dùng public...II CÁC LOẠI LAYOUT MANAGER FlowLayout 2 c Hàm khởi tạo public FlowLayout() public FlowLayout(int align) public FlowLayout(int align, int hgap, int vgap) e Một số phương thức thường dùng public void addLayoutComponent(Component comp, Object constraints) II CÁC LOẠI LAYOUT MANAGER FlowLayout 2 d Một số phương thức thường dùng public int getAlignment... invalidateLayout(Container target) II CÁC LOẠI LAYOUT MANAGER BoxLayout 3 d Một số phương thức thường dùng public void addLayoutComponent(String name, Component comp) public void removeLayoutComponent(Component comp) public void addLayoutComponent(Component comp, Object constraints) public Demention preferredLayoutSize(Container target) public Demention minimumLayoutSize(Container target) II CÁC LOẠI LAYOUT. .. GroupLayout.SequentialGroup createSequentialGroup() public boolean getAutoCreateGaps() Tham khảo thêm tại nguồn: http://docs.oracle.com/javase/7/docs/api/java/awt/GridBagLayout.ht ml   II CÁC LOẠI LAYOUT MANAGER Spring layout 8 a Đặc điểm: .Các components được đặt lên có liên quan với nhau .… b Cú pháp khai báo public class SpringLayout extends Object implements LayoutManager2 II CÁC LOẠI LAYOUT MANAGER. .. Rectangle r) public GroupLayout.ParallelGroup createBaselineGroup(boolean resizeable, boolean anchorBaselineToTop) public GroupLayout.ParallelGroup createParallelGroup() public GroupLayout.ParallelGroup createParallelGroup( GroupLayout.Alignment alignment) II CÁC LOẠI LAYOUT MANAGER Group layout 7 d Các phương thức thường dùng public GroupLayout.ParallelGroup createParallelGroup( GroupLayout.Alignment alignment,... và ngược lại  Sử dụng hai loại sắp xếp – tuần tự và song song, kết hợp với thành phần thứ bậc  Thêm khoảng cách giữa các component một cách tự động, những khoảng cách này được tính toán dựa trên look-and-feel thực sự II CÁC LOẠI LAYOUT MANAGER Group layout 7 a Đặc điểm:  Tất cả các thành phần được lưu giữ kích thước mặc định của nó  Không này b có sub-panel được sử dụng để xây dựng trong trường ... loại Layout manager Các loại LayoutManager hổ trợ java bao gồm: .BorderLayout .FlowLayout .BoxLayout .CardLayout .GridLayout .GridBagLayout .GroupLayout .SpringLayout II CÁC LOẠI LAYOUT MANAGER. .. có kiểu Layout FlowLayout Cú pháp khai báo public class FlowLayout extends Object implements LayoutManager, Serializable II CÁC LOẠI LAYOUT MANAGER FlowLayout c Hàm khởi tạo public FlowLayout()... pháp khai báo public class BoxLayout extends Object implements LayoutManager LayoutManager2, Serializable II CÁC LOẠI LAYOUT MANAGER BoxLayout c Hàm khởi tạo public BoxLayout(Container target, int

Ngày đăng: 10/10/2015, 14:17

Từ khóa liên quan

Mục lục

  • SỬ DỤNG LAYOUT MANAGER TRONG THIẾT KẾ GIAO DIỆN

  • NỘI DUNG

  • GIỚI THIỆU

  • GIỚI THIỆU

  • GIỚI THIỆU

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

  • CÁC LOẠI LAYOUT MANAGER

Tài liệu cùng người dùng

Tài liệu liên quan