Professional Documents
Culture Documents
Ni dung
JFrame
JDialog
JDesktopPane & JInternalFrame JPanel
JFrame Hnh nh
JFrame
JFrame c s dng lm giao din chnh trong ng dng Swing (top-level windows) Hu ht cc ng dng Swing c xy dng t JFrame
public FrameName() { this.initComponents(); } /** * Khi to cc thnh phn */ private void initComponents() { ... pack(); }
}
JFrame Hin th
1 2 3 4 5 6 7 8 9 package packageName;
public class Main { public static void main(String[] args) { FrameName frm = new FrameName(); frm.setVisible(true); } }
WindowContants.DISPOSE_ON_CLOSE
WindowContants.EXIT_ON_CLOSE
JFrame.ICONIFIED
JFrame.MAXIMIZED_HORIZ JFrame.MAXIMIZED_VERT
JFrame.MAXIMIZED_BOTH
Gn mu ch cho JFrame
9
10
11
Jframe V d 1
12
JFrame V d 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
13
package swingcontainersample; import javax.swing.*; public class ViDu1Frame extends JFrame{ public ViDu1Frame() { super(); this.initComponents(); } private void initComponents() { this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); ImageIcon icon=new ImageIcon( this.getClass().getResource("images/java-icon.jpg") ); this.setIconImage(icon.getImage()); this.setTitle("V d 1"); this.setLocation(0, 0); this.setSize(300, 400); this.setExtendedState(JFrame.NORMAL); } }
JFrame V d 1
1 2 3 4 5 6 7 8 9 package swingcontainersample;
public class Main { public static void main(String[] args) { ViDu1Frame frm = new ViDu1Frame(); frm.setVisible(true); } }
14
JFrame V d 2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
15
package swingcontainersample; import javax.swing.*; public class ViDu2Frame extends JFrame { private JButton jbt1; public ViDu2Frame() { super(); this.initComponents(); } private void initComponents() { //JFrame this.setTitle("V d 2"); this.setSize(200, 100); this.setExtendedState(JFrame.NORMAL); //Buton this.jbt1=new JButton(); this.jbt1.setText("Button 1"); this.add(this.jbt1); } }
JDialog Hnh nh
16
JDialog
JFrame hay JDialog thng s dng JDialog nhp liu hoc xut liu JDialog c 2 trng thi Modal: Khi Jdialog thc hin xong mi c php thao tc ln form cha . Modeless: Sau khi hin th dialog, ngi dng c th thao tc ln form cha JDialog thng c s dng vi trng thi Modal
17
19
20
WindowContants.DISPOSE_ON_CLOSE
21
Gn mu ch cho JFrame
22
23
24
JDesktopPane Hnh nh
MDI
JDesktopPane
25
JDesktopPane
JDesktopPane c s dng xy dng ng dng MDI JDesktopPane thng l mt thnh phn bn trong JFrame JDesktopPane thng c s dng cha cc JInternalFrame bn trong
26
Ly tt c cc JInternalFrame bn trong
27
JInternalFrame Hnh nh
JDesktopPane
MDI
28
JInternalFrame
JInternalFrame c s dng a vo bn trong JDesktopPane ca JFrame xy dng ng dng MDI. Cc bc xy dng ng dng MDI: Bc 1: Xy dng mt hay nhiu JInternalFrame Bc 2:To mt JFrame c mt JDesktopPane bn trong Bc 3: Gn JInternalFrame vo bn trong JDesktopPane
29
30
JPanel Hnh nh
31
JPanel
JPanel c s dng gom nhm cc control bn trong, c th c s dng nh mt user control JPanel c s dng nh mt thnh phn bn trong JFrame, JDialog, JInternalFrame, hoc trong mt Jpanel khc.
32
33
HI V P
34