Lecture Java: Chapter 12
Số trang: 59
Loại file: pptx
Dung lượng: 1.93 MB
Lượt xem: 30
Lượt tải: 0
Xem trước 6 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Lecture Java: Chapter 12 (Java Graphic User Interface) focuses on How to display a Window, Layout Manager, Common Control, Event Listener, Event Listener, Event Listener.
Nội dung trích xuất từ tài liệu:
Lecture Java: Chapter 12DONG NAI UNIVERSITY OF TECHNOLOGY 1 DONG NAI UNIVERSITY OF TECHNOLOGY ContactFull Name: Trần Duy ThanhBlog : http://duythanhcse.wordpress.comEmail: tranduythanh@dntu.edu.vnPhone: 0987773061 2 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window? 2. Layout Manager 3. Common Control4. Event Listener5. Dialogbox6. Advanced Control 3 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?Ø Extends from Frame or JFrame? import java.awt.*; import java.awt.event.*; import javax.swing.*; 4 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?public class MyWindow extends JFrame{ public MyWindow(){ super(Demo Windows);setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[]args) { MyWindow ui=new MyWindow(); ui.setSize(400, 300); ui.setLocationRelativeTo(null); ui.setVisible(true); 5 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?super(Demo Windows); Use to set title for this windowsetDefaultCloseOperation(EXIT_ON_CLOSE); Allow click ‘x’ Top right cornerto close the windowui.setSize(400, 300); set Width =400 and Height =300ui.setLocationRelativeTo(null); Display window on desktop centerscreenui.setVisible(true); 6 DONG NAI UNIVERSITY OF TECHNOLOGY2. Layout Manager Ø FlowLayout Ø BoxLayout Ø BorderLayout - Setting up the Layout before add another control. Ø CardLayout - Usually, we use JPanel to Ø GridBagLayout add another control, JPanel Ø GridLayout is container. JPanel could add another JPanel. Ø GroupLayout Ø SpringLayout 7 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayout FlowLayout cho phép add các control trên cùng một dòng, 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 control. 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. Resize the Width 8 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayout Code E:HUIJavaStudyJPanel pnFlow=new JPanel(); hocuisrcMyFlowLayout. pnFlow.setLayout(new FlowLayout());pnFlow.setBackground(Color.PINK);JButton btn1=new JButton(FlowLayout);JButton btn2=new JButton(Add cáccontrol);JButton btn3=new JButton(Trên 1 dòng);JButton btn4=new JButton(Hết chỗchứa);JButton btn5=new JButton(Thì xuốngdòng);pnFlow.add(btn1);pnFlow.add(btn2);pnFlow.add(btn3);pnFlow.add(btn4); 9 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayoutpnFlow.setLayout(new FlowLayout()); Setup FlowLayout for pnFlowpnFlow.add(btn1); Add new button into the pnFlowContainer con=getContentPane(); get the Window containercon.add(pnFlow); add pnFlow panel into the windowcontainer 10 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayoutBoxLayout cho phép add các control theo dòng hoặccột, tại mỗi vị trí add nó chỉ chấp nhận 1 control, dođó muốn xuất hiện nhiều control tại một vị trí thì bạnnên add vị trí đó là 1 JPanel rồi sau đó add cáccontrol khác vào JPanel này.BoxLayout.X_AXIS cho phép add các control theohướng từ trái qua phải.BoxLayout.Y_AXIS cho phép add các control theohướng từ trên xuống dưới.BoxLayout sẽ không tự động xuống dòng khi hếtchỗ chứa, tức là các control sẽ bị che khuất nếu nhưthiếu không gian chứa nó. 11 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayout BoxLayout.X_AXIS BoxLayout.Y_AXIS No wrap row when resize dimension 12 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayout E:HUIJavaStudy Code hocuisrcMyBoxLayout.jJPanel pnBox=new JPanel();pnBox.setLayout(new BoxLayout(pnBox,BoxLayout.X_AXIS));JButton btn1=new JButton(BoxLayout);btn1.setForeground(Color.RED);Font font=new Font(Arial,Font.BOLD |Font.ITALIC, ...
Nội dung trích xuất từ tài liệu:
Lecture Java: Chapter 12DONG NAI UNIVERSITY OF TECHNOLOGY 1 DONG NAI UNIVERSITY OF TECHNOLOGY ContactFull Name: Trần Duy ThanhBlog : http://duythanhcse.wordpress.comEmail: tranduythanh@dntu.edu.vnPhone: 0987773061 2 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window? 2. Layout Manager 3. Common Control4. Event Listener5. Dialogbox6. Advanced Control 3 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?Ø Extends from Frame or JFrame? import java.awt.*; import java.awt.event.*; import javax.swing.*; 4 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?public class MyWindow extends JFrame{ public MyWindow(){ super(Demo Windows);setDefaultCloseOperation(EXIT_ON_CLOSE); } public static void main(String[]args) { MyWindow ui=new MyWindow(); ui.setSize(400, 300); ui.setLocationRelativeTo(null); ui.setVisible(true); 5 DONG NAI UNIVERSITY OF TECHNOLOGY1. How to display a Window?super(Demo Windows); Use to set title for this windowsetDefaultCloseOperation(EXIT_ON_CLOSE); Allow click ‘x’ Top right cornerto close the windowui.setSize(400, 300); set Width =400 and Height =300ui.setLocationRelativeTo(null); Display window on desktop centerscreenui.setVisible(true); 6 DONG NAI UNIVERSITY OF TECHNOLOGY2. Layout Manager Ø FlowLayout Ø BoxLayout Ø BorderLayout - Setting up the Layout before add another control. Ø CardLayout - Usually, we use JPanel to Ø GridBagLayout add another control, JPanel Ø GridLayout is container. JPanel could add another JPanel. Ø GroupLayout Ø SpringLayout 7 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayout FlowLayout cho phép add các control trên cùng một dòng, 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 control. 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. Resize the Width 8 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayout Code E:HUIJavaStudyJPanel pnFlow=new JPanel(); hocuisrcMyFlowLayout. pnFlow.setLayout(new FlowLayout());pnFlow.setBackground(Color.PINK);JButton btn1=new JButton(FlowLayout);JButton btn2=new JButton(Add cáccontrol);JButton btn3=new JButton(Trên 1 dòng);JButton btn4=new JButton(Hết chỗchứa);JButton btn5=new JButton(Thì xuốngdòng);pnFlow.add(btn1);pnFlow.add(btn2);pnFlow.add(btn3);pnFlow.add(btn4); 9 DONG NAI UNIVERSITY OF TECHNOLOGYØ FlowLayoutpnFlow.setLayout(new FlowLayout()); Setup FlowLayout for pnFlowpnFlow.add(btn1); Add new button into the pnFlowContainer con=getContentPane(); get the Window containercon.add(pnFlow); add pnFlow panel into the windowcontainer 10 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayoutBoxLayout cho phép add các control theo dòng hoặccột, tại mỗi vị trí add nó chỉ chấp nhận 1 control, dođó muốn xuất hiện nhiều control tại một vị trí thì bạnnên add vị trí đó là 1 JPanel rồi sau đó add cáccontrol khác vào JPanel này.BoxLayout.X_AXIS cho phép add các control theohướng từ trái qua phải.BoxLayout.Y_AXIS cho phép add các control theohướng từ trên xuống dưới.BoxLayout sẽ không tự động xuống dòng khi hếtchỗ chứa, tức là các control sẽ bị che khuất nếu nhưthiếu không gian chứa nó. 11 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayout BoxLayout.X_AXIS BoxLayout.Y_AXIS No wrap row when resize dimension 12 DONG NAI UNIVERSITY OF TECHNOLOGYØ BoxLayout E:HUIJavaStudy Code hocuisrcMyBoxLayout.jJPanel pnBox=new JPanel();pnBox.setLayout(new BoxLayout(pnBox,BoxLayout.X_AXIS));JButton btn1=new JButton(BoxLayout);btn1.setForeground(Color.RED);Font font=new Font(Arial,Font.BOLD |Font.ITALIC, ...
Tìm kiếm theo từ khóa liên quan:
Kỹ thuật lập trình Lecture Java Chapter 12 Lập trình Java Lập trình Mobile Ngôn ngữ lập trình Công nghệ thông tinGợi ý tài liệu liên quan:
-
52 trang 429 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 312 0 0 -
74 trang 295 0 0
-
96 trang 291 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 278 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 274 0 0 -
Giáo trình Lập trình hướng đối tượng: Phần 2
154 trang 272 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Bài thuyết trình Ngôn ngữ lập trình: Hệ điều hành Window Mobile
30 trang 264 0 0