swing的容器有两类一个是JFrame,一个是JDialog。
1.JFrame和JDialog的区别
JFrame是最常用的窗体型容器,默认情况下,在右上角有最大化最小化按钮
JDialog也是窗体型容器,右上角没有最大和最小化按钮
代码如下:
package gui3;
import javax.swing.JButton;
import javax.swing.JFrame;
public class test1 {
public static void main(String[] args) {
JFrame f = new JFrame("123");
f.setSize(400,300);
f.setLocation(200,200);
f.setLayout(null);
JButton b = new JButton("456");
b.setBounds(50, 50, 280, 30);
f.add(b);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
运行结果:
package gui3;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class test2 {
public static void main(String[] args) {
JDialog f