您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > java商品管理系统2
//注册页面packagecom.gui;importjava.awt.*;importjavax.swing.*;importjavax.swing.plaf.ButtonUI;importcom.DateSystem.Userdate;importjava.awt.event.*;importjava.sql.*;publicclassRegisterextendsJFrameimplementsActionListener,KeyListener,FocusListener{//注册组件JLabellbl_name,lbl_password,lbl_repassword,lbl_sex,lbl_id;//用户名,密码标签JLabellbl_post,lbl_phon,lbl_email,lbl_address;//地址之类的标签JLabellbl_name_tishi,lbl_password_tishi,lbl_repassword_tishi,lbl_sex_tishi,lbl_id_tishi;//提示标签JTextFieldtext_name,text_id,text_post,text_phon,text_email,text_address;//输入文本框JPasswordFieldpassword,repassword;//密码的输入文本框CheckboxGroupgroup;Checkboxsex_m;Checkboxsex_w;//JRadioButtonsex_m,sex_w;//ButtonGroupbg=newButtonGroup();//分组用来制作单选框JButtonbutton_submit,button_exit;//按钮JPaneljPanel;//装载容器publicRegister(){super(用户注册);//标签组建的初始化//用户基本信息lbl_name=newJLabel(用户名:);lbl_password=newJLabel(密码:);lbl_repassword=newJLabel(确认密码:);lbl_sex=newJLabel(性别:);lbl_id=newJLabel(身份证号:);//详细信息lbl_post=newJLabel(职位:);lbl_phon=newJLabel(手机号:);lbl_email=newJLabel(E—mail:);lbl_address=newJLabel(住址:);//提示信息lbl_name_tishi=newJLabel(请输入您的真实姓名!);lbl_password_tishi=newJLabel(请输入密码!);lbl_repassword_tishi=newJLabel(两次输入不一样,请重新输入!);lbl_sex_tishi=newJLabel(请选择性别!);lbl_id_tishi=newJLabel(请填写您的身份证号!);//输入框组件的初始化//基本信息输入框text_name=newJTextField();password=newJPasswordField();repassword=newJPasswordField();//详细信息输入框text_id=newJTextField();text_post=newJTextField();text_phon=newJTextField();text_email=newJTextField();text_address=newJTextField();//性别组件group=newCheckboxGroup();sex_m=newCheckbox(男,group,true);sex_w=newCheckbox(女,group,false);//按钮组件的初始化button_submit=newJButton(提交);button_exit=newJButton(取消);//设置字体,自号Fontfont=newFont(Serif,Font.BOLD,18);//向容器添加组件jPanel=newJPanel();//创建容器jPanel.setLayout(null);//设置组件布局,我这里用的是坐标,因为这样界面会整齐些lbl_name.setBounds(50,50,90,20);lbl_password.setBounds(50,80,90,20);lbl_repassword.setBounds(50,110,90,20);lbl_sex.setBounds(50,140,90,20);lbl_id.setBounds(50,170,90,20);lbl_post.setBounds(50,230,90,20);lbl_phon.setBounds(50,260,90,20);lbl_email.setBounds(50,290,90,20);lbl_address.setBounds(50,320,90,20);//输入框组件的添加text_name.setBounds(150,50,200,20);password.setBounds(150,80,200,20);repassword.setBounds(150,110,200,20);sex_m.setBounds(170,140,40,20);//性别选择框sex_w.setBounds(270,140,40,20);text_id.setBounds(150,170,200,20);text_post.setBounds(150,230,200,20);text_phon.setBounds(150,260,200,20);text_email.setBounds(150,290,200,20);text_address.setBounds(150,320,200,20);button_submit.setBounds(150,370,90,30);button_exit.setBounds(300,370,90,30);//提示组件添加//lbl_name_tishi.setBounds(360,50,200,20);//lbl_password_tishi.setBounds(360,80,200,20);//lbl_repassword_tishi.setBounds(360,110,200,20);lbl_name.setFont(font);lbl_password.setFont(font);lbl_repassword.setFont(font);lbl_sex.setFont(font);lbl_id.setFont(font);lbl_post.setFont(font);lbl_phon.setFont(font);lbl_address.setFont(font);lbl_email.setFont(font);jPanel.add(lbl_name);jPanel.add(lbl_password);jPanel.add(lbl_repassword);jPanel.add(lbl_sex);jPanel.add(lbl_id);jPanel.add(lbl_post);jPanel.add(lbl_phon);jPanel.add(lbl_email);jPanel.add(lbl_address);jPanel.add(text_name);jPanel.add(password);jPanel.add(repassword);/*ButtonGroup不需要加入JPanel里面ButtonGroup用于为一组按钮创建一个多斥(multiple-exclusion)作用域。使用相同的ButtonGroup对象创建一组按钮意味着“开启”其中一个按钮时,将关闭组中的其他所有按钮。你只需要定义一个ButtonGroup,然后将button加入其中,至于加入的这些button在不在同一个JPanel里都是可以的。ButtonGroup并不能算是一个装载的容器*/jPanel.add(sex_m);jPanel.add(sex_w);jPanel.add(text_id);jPanel.add(text_post);jPanel.add(text_phon);jPanel.add(text_email);jPanel.add(text_address);jPanel.add(button_submit);jPanel.add(button_exit);jPanel.add(lbl_name_tishi);jPanel.add(lbl_password_tishi);jPanel.add(lbl_repassword_tishi);jPanel.add(lbl_sex_tishi);jPanel.add(lbl_id_tishi);add(jPanel);//注册监听//sex_m.addItemListener(this);//sex_w.addItemListener(this);button_exit.addActionListener(this);button_submit.addActionListener(this);//文本框焦点事件监听text_name.addFocusListener(this);password.addFocusListener(this);repassword.addFocusListener(this);text_id.addFocusListener(this);}publicstaticvoidmain(String[]args){Registerregister=newRegister();register.setSize(600,470);register.setLocationRelativeTo(null);register.setVisible(true);register.setResizable(false);//register.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}@OverridepublicvoidkeyTyped(KeyEvente){//TODOAuto-generatedmethodstub}@OverridepublicvoidkeyPressed(KeyEvente){//TODOAuto-generatedmethodstub}@OverridepublicvoidkeyReleased(KeyEvente){//TODOAuto-generatedmethodstub}@Override//文本框焦点事件处理publicvoidfocusGained(FocusEvente){//TODOAuto-generatedmethodstub}@OverridepublicvoidfocusLost(FocusEvente){//TODOAuto-generatedmethodstubStringnameString=text_name.getText().trim();Stringpass=String.valueOf(password.getPassword());Stringrepass=String.valueOf(repassword.getPassword());StringidString=text_id.getText();if(e.getSource()==text_name){if(nameString.equals()){System.out.println(用户名为空);lbl_name_tishi.setText(o(︶︿︶)o唉!用户名不能为空!);lbl_name_tishi.setBounds(360,50,200,20);lbl_name_tishi.setForegroun
本文标题:java商品管理系统2
链接地址:https://www.777doc.com/doc-4620497 .html