day 26

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值