知识要点:
关于身份证的录入,我们先的掌握,身份证号码代表的属性 ,在通过属性的定义进行程序编写。同时也得注意算法。
package f;
import javax.swing.*;
import java.awt.*;
public class RegisterTest extends JFrame{//创建类RegisterTest继承于类JFrame
JPanel pnlMain;
JLabel lblUser,lblPassword,lblSurePassword,lblSex,lblIdentify,lblHobby,lblCity;
JTextField txtUser;
JPasswordField pwdPassword1,pwdPassword2;
JRadioButton rbtnMale,rbtnFemale;
JCheckBox chk1,chk2,chk3;
ButtonGroup grpSex;
JButton btnExit,btnLogin;
List lstSize;
JComboBox cmbType;
String[] strType= {“身份证”,”学生证”};//6~15行:定义变量
public RegisterTest(){
super(“注册页面”);//设置页面标题
lblUser=new JLabel(“用户名”);
lblPassword=new JLabel(“密 码”);
lblSurePassword=new JLabel(“确认密码”);
lblUser.setSize(getMaximumSize());
lblSex=new JLabel(“性 别”);
lblIdentify=new JLabel(“有效证件”);
lblHobby=new JLabel(“爱 好”);
lblCity=new JLabel(“城 市”);//18~25行:定义标签
txtUser=new JTextField(10);
pwdPassword1=new JPasswordField(10);
pwdPassword2=new JPasswordField(10);//26~28行:定义文本框和密码框
grpSex=new ButtonGroup();
rbtnMale=new JRadioButton(“男”);
grpSex.add(rbtnMale);
rbtnMale.setSelected(true);
rbtnFemale=new JRadioButton(“女”);
grpSex.add(rbtnFemale);//29~34行:定义单选按钮
cmbType=new JComboBox(strType);
cmbType.setSelectedIndex(0);//35~36行:定义下拉列表框
chk1=new JCheckBox(“运动”);
chk2=new JCheckBox(“唱歌”);
chk3=new JCheckBox(“篮球”);//37~39行:定义复选框
lstSize=new List();
lstSize.add(“南京”);
lstSize.add(“苏州”);
lstSize.add(“东京”);
lstSize.add(“上海”);
lstSize.add(“杭州”);
lstSize.add(“扬州”);
lstSize.add(“徐州”);
lstSize.select(0);//40~48定义列表
JButton btnLogin = new JButton(“确定”);
Component btnExit = new JButton(“取消”);//49~50行:定义“确定”和“取消”按钮
pnlMain=new JPanel();
pnlMain.add(lblUser);
pnlMain.add(txtUser);
pnlMain.add(lblPassword);
pnlMain.add(pwdPassword1);
pnlMain.add(lblSurePassword);
pnlMain.add(lblSex);
pnlMain.add(rbtnMale);
pnlMain.add(rbtnFemale);
pnlMain.add(lblIdentify);
pnlMain.add(cmbType);
pnlMain.add(lblHobby);
pnlMain.add(chk1);
pnlMain.add(chk2);
pnlMain.add(chk3);
pnlMain.add(lblCity);
pnlMain.add(lstSize);
pnlMain.add(btnLogin);
pnlMain.add(btnExit);
pnlMain.setLayout(null);//52~70行:在容器(界面)中添加组件
lblUser.setBounds(30,10,60,25);
lblPassword.setBounds(30,40,60,25);
lblSurePassword.setBounds(30,70,60,25);
txtUser.setBounds(100,10,150,25);
pwdPassword1.setBounds(100,40,150,25);
pwdPassword2.setBounds(100,70,150,25);
lblSex.setBounds(30,100,60,25);
rbtnMale.setBounds(100,100,60,25);
rbtnFemale.setBounds(160,100,60,25);
lblIdentify.setBounds(30,130,60,25);
cmbType.setBounds(100,130,80,25);
lblHobby.setBounds(30,160,60,25);
chk1.setBounds(100,160,60,25);
chk2.setBounds(160,160,60,25);
chk3.setBounds(220,160,60,25);
lblCity.setBounds(30,190,60,25);
lstSize.setBounds(100,190,80,25);
btnLogin.setBounds(40,256,80,25);
btnExit.setBounds(160,256,80,25);//71~90行:采用unll布局组件在界面中的位置
this.setContentPane(pnlMain);
setSize(300,330);
setVisible(true);//设置页面的大小、可见性等性质
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new RegisterTest();
}
}
总结:
通过学习,熟悉和掌握了这个程序。