效果
Register.java
public class Register extends JFrame {
public Register(){
// 设置标题
this.setTitle("用户注册");
// 窗口大小
this.setSize(488, 430);
// 压过其他软件,放置最上方
this.setAlwaysOnTop(true);
// 设置居中打开
this.setLocationRelativeTo(null);
// 设置关闭游戏(这里的关闭指Java虚拟机运行也关闭,不是视觉上的关闭)
this.setDefaultCloseOperation(3);
// 布局
this.setLayout(new GridLayout(8 ,1));
// 用户名
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel("用户名");
jPanel1.add(jLabel1);
JTextField jTextField1 = new JTextField(15);
jPanel1.add(jTextField1);
this.add(jPanel1);
// 密码
JPanel jPanel2 = new JPanel();
JLabel jLabel2 = new JLabel("密码");
jPanel2.add(jLabel2);
JPasswordField jPasswordField2 = new JPasswordField(15);
jPanel2.add(jPasswordField2);
this.add(jPanel2);
// 确认密码
JPanel jPanel3 = new JPanel();
JLabel jLabel3 = new JLabel("确认密码");
jPanel3.add(jLabel3);
JPasswordField jPasswordField3 = new JPasswordField(15);
jPanel3.add(jPasswordField3);
this.add(jPanel3);
// 性别
JPanel jPanel4 = new JPanel();
JLabel jLabel4 = new JLabel("性别");
jPanel4.add(jLabel4);
JRadioButton jRadioButton1 = new JRadioButton("男");
jPanel4.add(jRadioButton1);
JRadioButton jRadioButton2 = new JRadioButton("女");
jPanel4.add(jRadioButton2);
this.add(jPanel4);
// 爱好
JPanel jPanel5 = new JPanel();
JLabel jLabel5 = new JLabel("爱好");
jPanel5.add(jLabel5);
JCheckBox jCheckBox1 = new JCheckBox("阅读");
jPanel5.add(jCheckBox1);
JCheckBox jCheckBox2 = new JCheckBox("上网");
jPanel5.add(jCheckBox2);
JCheckBox jCheckBox3 = new JCheckBox("游泳");
jPanel5.add(jCheckBox3);
JCheckBox jCheckBox4 = new JCheckBox("旅游");
jPanel5.add(jCheckBox4);
this.add(jPanel5);
// 地址
JPanel jPanel6 = new JPanel();
JLabel jLabel6 = new JLabel("地址");
jPanel6.add(jLabel6);
JTextArea jTextArea = new JTextArea(3, 20);
jPanel6.add(jTextArea);
this.add(jPanel6);
// 学历
JPanel jPanel7 = new JPanel();
JLabel jLabel7 = new JLabel("学历");
jPanel7.add(jLabel7);
String[] degree = {"A","B","C","D"};
JComboBox<String> jComboBox = new JComboBox<>(degree);
jPanel7.add(jComboBox);
this.add(jPanel7);
JPanel jPanel8 = new JPanel();
JButton jButton1 = new JButton("注册");
jPanel8.add(jButton1);
JButton jButton2 = new JButton("取消");
jPanel8.add(jButton2);
this.add(jPanel8);
// 设置窗口是否显示,默认为false
this.setVisible(true);
}
public static void main(String[] args) {
new Register();
}
}