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);
}
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);
}