JFrame窗体类
package Demo01;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JDialog;
import javax.swing.JLabel;
public class JDialogTest extends JDialog{
public JDialogTest() {
setVisible(true);
}
public static void main(String[] args) {
// new JDialogTest();
JDialog jd = new JDialog();
jd.setVisible(true);
jd.setBounds(200,200,400,400);
Container c =jd.getContentPane();
c.add(new JLabel("这是一个标签"));
c.setBackground(Color.pink);
}
}
package Demo01;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
public class JDialogTest2 extends JDialog{
public JDialogTest2(JFrame frame) {
super(frame,“对话框标签”,true);
setVisible(true);
setBounds(100,100,200,300);
}
public static void main(String[] args) {
JFrame f = new JFrame(“父窗体”);
f.setBounds(50, 50, 300, 300);
Container c = f.getContentPane();
JButton btn = new JButton(“弹出对话框”);
c.setLayout(new FlowLayout());
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JDialogTest2 jd = new JDialogTest2(f);
jd.setVisible(true);
}
});
new jFrameTest();
}
}
package Demo01;
import java.awt.Color;
import java.awt.Container;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class jFrameTest extends JFrame{
public jFrameTest() {
// JFrame f = new JFrame(“大数据2005”);//创建窗体对象,在参数中设置窗体标记
// 设置窗体可见
setVisible(true);
// 注意:点击关闭没有结束程序的运行
/*
* EXIT_ON_CLOSE:隐藏窗体,并终止程序
* EXIT_ON_CLOSE:无任何操作
* HIDE_ON_CLOSE:隐藏窗体,但是不终止程序
* DISPOSE_ON_CLOSE:释放窗体资源
* */
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocation(600,300);//设置位置,单位是像素,从左上角0,0开始
setSize(500, 350);//设置窗体大小,单位:像素
Container c = getContentPane();
c.setBackground(Color.gray);//设置颜色
JLabel l = new JLabel(“你瞅啥”);
c.add(l);//添加组件
// c.remove(l);//移除组件
c.validate();
setContentPane©;
setResizable(true);
// setBounds(500, 200,400, 400);
}
public static void main(String[] args) {
JFrame f = new JFrame(“大数据2005”);
new jFrameTest();
}
}
2020080605030