GUI框体

public class Gui1 extends JFrame {
public Gui1(){
this.setTitle("我的窗体");
//设置窗体的布局管理器,null布局的含义是,使用组件的大小和位置定位组件
this.setLayout(null);

//标签组件
JLabel j1 = new JLabel("姓名");
//设置标签的位置和大小
j1.setBounds(60,50,80,20);
//将标签加入窗体
this.add(j1);

//文本框组件
JTextField jtxt = new JTextField();
jtxt.setBounds(100,50,120,20);
this.add(jtxt);
//创建图片标签
JLabel imgLabel = new JLabel();
//得到图像
Image img = new ImageIcon("img/6.jpg").getImage();
//将图像缩放到200x200像素
img = img.getScaledInstance(300, 300, 1);
//设置标签的图片
imgLabel.setIcon(new  ImageIcon(img));
imgLabel.setBounds(0,0, 200, 200);
this.add(imgLabel);

//按钮
JButton button = new JButton("确定");
button.setBounds(200,350,80,20);
this.add(button);

//下拉框
JComboBox box = new JComboBox();
box.addItem("小学");
box.addItem("初中");
box.addItem("高中");
box.setBounds(400,350,120,20);
this.add(box);


//单选项
JRadioButton radio1 = new  JRadioButton("男");
radio1.setBounds(300,50,80,20);
this.add(radio1);

JRadioButton radio2 = new  JRadioButton("女");
radio2.setBounds(400,50,80,20);
this.add(radio2);

//完成单选框互斥
ButtonGroup bg = new  ButtonGroup();
bg.add(radio1);
bg.add(radio2);

//复选框
JCheckBox jc = new JCheckBox("记住密码");
jc.setBounds(300,400,80,20);
this.add(jc);

this.setSize(300,300);
this.setVisible(true);
this.setDefaultCloseOperation(3);
this.setLocationRelativeTo(null);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值