Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
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. | 1 1 Full Name: Trần Duy Thanh Blog : http://duythanhcse.wordpress.com Email: tranduythanh@dntu.edu.vn Phone: 0987773061 Contact 2 2 2. Layout Manager 3. Common Control 4. Event Listener 6. Advanced Control 3 1. How to display a Window? 5. Dialogbox 4 1. How to display a Window? Extends from Frame or JFrame? import javax.swing.*; import java.awt.*; import java.awt.event.*; 5 1. 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); } } 6 1. How to display a Window? super("Demo Windows"); Use to set title for this window setDefaultCloseOperation(EXIT_ON_CLOSE); Allow click ‘x’ Top right corner to close the window ui.setSize(400, 300); set Width =400 and Height =300 ui.setLocationRelativeTo(null); Display window on desktop center screen . | 1 1 Full Name: Trần Duy Thanh Blog : http://duythanhcse.wordpress.com Email: tranduythanh@dntu.edu.vn Phone: 0987773061 Contact 2 2 2. Layout Manager 3. Common Control 4. Event Listener 6. Advanced Control 3 1. How to display a Window? 5. Dialogbox 4 1. How to display a Window? Extends from Frame or JFrame? import javax.swing.*; import java.awt.*; import java.awt.event.*; 5 1. 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); } } 6 1. How to display a Window? super("Demo Windows"); Use to set title for this window setDefaultCloseOperation(EXIT_ON_CLOSE); Allow click ‘x’ Top right corner to close the window ui.setSize(400, 300); set Width =400 and Height =300 ui.setLocationRelativeTo(null); Display window on desktop center screen ui.setVisible(true); Show the window 2. Layout Manager 7 FlowLayout BoxLayout BorderLayout CardLayout GridBagLayout GridLayout GroupLayout SpringLayout - Setting up the Layout before add another control. - Usually, we use JPanel to add another control, JPanel is container. JPanel could add another JPanel. 8 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 9 FlowLayout JPanel pnFlow=new JPanel(); pnFlow.setLayout(new FlowLayout()); pnFlow.setBackground(Color.PINK); JButton btn1=new JButton("FlowLayout"); JButton btn2=new JButton("Add các control"); JButton btn3=new JButton("Trên 1 dòng"); JButton btn4=new JButton("Hết chỗ chứa"); JButton btn5=new JButton("Thì xuống dòng"); pnFlow.add(btn1);pnFlow.add(btn2); pnFlow.add(btn3);pnFlow.add(btn4); pnFlow.add(btn5); Container .