package gui.compont;
import javax.swing.*;
import java.awt.*;
import java.net.URL;
/**
* @author 华瑞汤永红
* @version 1.0
* @data 2022-11-21 9:28
*/
public class RegisterForm extends JFrame {
/**
* 编号(序号)
*/
JLabel lblId;
JTextField txtId;
/**
* 学号
*/
JLabel lblSid;
JTextField txtSid;
/**
* 姓名
*/
JLabel lblName;
JTextField txtName;
/**
* 身份证
*/
JLabel lblIdCard;
JTextField txtIdCard;
/**
* 爱好
*/
JLabel lblHobbies;
JCheckBox cobGame;
JCheckBox cobCode;
JCheckBox cobSport;
/**
* 学历
*/
JLabel lblQue;
JComboBox comQue;
/**
* 电话
*/
JLabel lblPhone;
JTextField txtPhone;
/**
* 联系地址
*/
JLabel lblAddress;
JTextField txtAddress;
/**
* 备注
*/
JLabel lblComment;
JTextArea txtComment;
/**
* 头像
*/
JLabel lblHeadIcon;
JTextArea txtHeadIcon;
/**
* 婚否
*/
JLabel lblIsMarried;
JCheckBox ckIsMarried;
/**
*
*/
JButton btnReg;
JButton btnClose;
//
private ImageIcon image;
public RegisterForm() {
URL resource = RegisterForm.this.getClass().getClassLoader().getResource("images/logo.png");
Image image = resource != null ? Toolkit.getDefaultToolkit().getImage(resource) : null;
setIconImage(image);
setTitle("学员注册");
setSize(320, 700);
setLayout(null);
/**
* 编号
*/
lblId = new JLabel("编号");
txtId = new MyTextField();
//定位
lblId.setBounds(50, 30, 80, 30);
txtId.setLocation(100, 30);
/**
* 学号
*/
lblSid = new JLabel("学号");
txtSid = new MyTextField();
//定位
lblSid.setBounds(50, 80, 80, 30);
txtSid.setLocation(100, 80);
/**
* 姓名
*/
lblName = new JLabel("姓名");
txtName = new MyTextField();
lblName.setBounds(50, 130, 80, 30);
txtName.setLocation(100, 130);
/**
* 身份证
*/
lblIdCard = new JLabel("身份证");
txtIdCard = new MyTextField();
lblIdCard.setBounds(50, 180, 80, 30);
txtIdCard.setLocation(100, 180);
/**
* 爱好
*/
lblHobbies = new JLabel("爱好");
cobGame = new JCheckBox("游戏");
cobCode = new JCheckBox("编码");
cobSport = new JCheckBox("运动");
lblHobbies.setBounds(50, 230, 80, 30);
cobGame.setBounds(100, 230, 60, 30);
cobCode.setBounds(160, 230, 60, 30);
cobSport.setBounds(220, 230, 60, 30);
cobGame.setOpaque(false);
cobCode.setOpaque(false);
cobSport.setOpaque(false);
/**
* 学历
*/
lblQue = new JLabel("学历");
String names[] = {"请选择", "研究生", "本科", "大专"};
comQue = new JComboBox(names);
comQue.setOpaque(false);
lblQue.setBounds(50, 280, 80, 30);
comQue.setBounds(100, 280, 150, 30);
/**
* 电话
*/
lblPhone = new JLabel("电话");
txtPhone = new MyTextField();
lblPhone.setBounds(50, 330, 80, 30);
txtPhone.setLocation(100, 330);
/**
* 联系地址
*/
lblAddress = new JLabel("地址");
txtAddress = new MyTextField();
lblAddress.setBounds(50, 380, 80, 30);
txtAddress.setLocation(100, 380);
/**
* 备注
*/
lblComment = new JLabel("备注");
txtComment = new JTextArea();
lblComment.setBounds(50, 430, 80, 30);
txtComment.setBounds(100, 430, 150, 30);
/**
* 头像
*/
lblHeadIcon = new JLabel("头像");
txtHeadIcon = new JTextArea();
lblHeadIcon.setBounds(50, 480, 80, 30);
txtHeadIcon.setBounds(100, 480, 150, 30);
txtHeadIcon.setLocation(100, 480);
/**
* 婚否
*/
lblIsMarried = new JLabel("婚否");
ckIsMarried = new JCheckBox();
ckIsMarried.setOpaque(false);
lblIsMarried.setBounds(50, 530, 80, 30);
ckIsMarried.setBounds(100, 530, 120, 30);
btnReg = new JButton("注册");
btnClose = new JButton("关闭");
btnReg.setBounds(50, 580, 100, 30);
btnClose.setBounds(160, 580, 100, 30);
//
add(lblId);
add(txtId);
add(lblSid);
add(txtSid);
add(lblName);
add(txtName);
add(lblIdCard);
add(txtIdCard);
add(lblHobbies);
add(cobGame);
add(cobCode);
add(cobSport);
add(lblQue);
add(comQue);
add(lblPhone);
add(txtPhone);
add(lblAddress);
add(txtAddress);
add(lblComment);
add(txtComment);
add(lblHeadIcon);
add(txtHeadIcon);
add(lblIsMarried);
add(ckIsMarried);
add(btnReg);
add(btnClose);
//放背景
JLabel lblBg = new JLabel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
URL url = RegisterForm.this.getClass().getClassLoader().getResource("gui\\compont\\bg.PNG");
ImageIcon image = new ImageIcon(url);
image.paintIcon(this, g, 0, 0);
}
};
lblBg.setBounds(0, 0, 320, 700);
//lblBg.setOpaque(true);
//lblBg.setBackground(Color.PINK);
//C:\code\java106\s1\javabase\javaoop\src\gui\compont\bg.PNG
//URL url = RegisterForm.this.getClass().getClassLoader().getResource("gui\\compont\\bg.PNG");
//ImageIcon icon = new ImageIcon(url);
//lblBg.setIcon(icon);
add(lblBg);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
new RegisterForm();
}
}
class MyTextField extends JTextField {
public MyTextField() {
setOpaque(false);
setSize(150, 30);
//setBorder(null);
//setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
setBorder(BorderFactory.createLineBorder(Color.GRAY));
}
}