用户界面2

知识点:
1注意多种实例化的运用
2注意存储空间的运用
import javax.swing.*;
import java.awt.*;
public class RegisterTest extends JFrame{
JPanel pnlMain;//定义属性
JLabel lblUser,lblPassword,lblSurePassword,lblSex,lblIdentify,lblHobby,lblCity;
JTextField txtUser;
JPasswordField pwdPassword1,pwdPassword2;
JRadioButton rbtnMale,rbtnFemale;
JCheckBox chk1,chk2,chk3;
JButton btnExit,btnLogin;
ButtonGroup grpSex;
List lstSize;
JComboBox cmbType;
String[] strType= {“身份证”,”学生证”};
public RegisterTest(){//设置管理员
super(“注册页面”);
lblUser=new JLabel(“用户名:”);
lblPassword=new JLabel(“密码:”);
lblSurePassword=new JLabel(“确认密码:”);
lblSex=new JLabel(“性别:”);
lblIdentify=new JLabel(“有效证件:”);
lblHobby=new JLabel(“爱 好:”);
lblCity=new JLabel(“城 市:”);
txtUser=new JTextField(10);
pwdPassword1=new JPasswordField(10);
pwdPassword2=new JPasswordField(10);
grpSex=new ButtonGroup();
rbtnMale=new JRadioButton(“男”);
grpSex.add(rbtnMale);
rbtnMale.setSelected(true);
rbtnFemale=new JRadioButton(“女”);
grpSex.add(rbtnFemale);
cmbType=new JComboBox(strType);
cmbType.setSelectedIndex(0);
chk1=new JCheckBox(“运动”);
chk2=new JCheckBox(“音乐”);
chk3=new JCheckBox(“阅读”);
lstSize=new List();
lstSize.add(“南京”);
lstSize.add(“苏州”);
lstSize.add(“无锡”);
lstSize.add(“常州”);
lstSize.add(“南通”);
lstSize.add(“宿迁”);
lstSize.add(“扬州”);
lstSize.add(“徐州”);
lstSize.select(0);
btnLogin=new JButton(“确定”);
btnExit=new JButton(“取消”);
pnlMain=new JPanel();
pnlMain.add(lblUser);
pnlMain.add(txtUser);
pnlMain.add(lblPassword);
pnlMain.add(pwdPassword1);
pnlMain.add(pwdPassword1);
pnlMain.add(lblSurePassword);
pnlMain.add(pwdPassword2);
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);
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,80,25);
lstSize.setBounds(100,190,80,60);
btnLogin.setBounds(40,265,80,25);
btnExit.setBounds(160,265,80,25);
this.setContentPane(pnlMain);
setSize(300,340);
setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new RegisterTest();
}

}

这里写图片描述
总结:
用户界面这个章节,是以往程序的一种加深,比以往稍有复杂,但都大同小异。
属性定义, 实例话,都只是比以往有所增加。

阅读更多
文章标签: javaweb
个人分类: java
上一篇键盘输入数组
下一篇用java程序判断三角形的构成
博主设置当前文章不允许评论。

没有更多推荐了,返回首页

关闭
关闭
关闭