Demo entry 6623710

1

   

Submitted by anonymous on Jun 08, 2017 at 18:44
Language: Java. Code size: 5.4 kB.

package train;

import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.UIManager;

import org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper;

public class RegisterUI extends JFrame implements ActionListener,ItemListener {

   JLabel lb1, lb2,lb3,lb4,lb5,lb6; // 标签
   JTextField userName_TF, userPassword_TF,userPassConfirm_TF,userPhone_TF;// 输入框
   JButton register_btn,cancel_btn;
   JRadioButton man_jrb,women_jrb;
   ButtonGroup g ;
   Font font = new Font("方正姚体",0,15);
   private String userName,userPassword,userPhone,userSex="男";

   public RegisterUI(){

      JPanel jp[]= new JPanel[6];
      for(int i=0;i<jp.length;i++){
         jp[i]=new JPanel();
      }

      lb1 = new JLabel("    用户名  ");
      lb2 = new JLabel("   密    码  ");
      lb3 = new JLabel(" 确认密码 ");
      lb4 = new JLabel(" 手机号码 ");
      lb5 = new JLabel("   性 别    ");
      lb1.setFont(font);
      lb2.setFont(font);
      lb3.setFont(font);
      lb4.setFont(font);
      lb5.setFont(font);

      man_jrb =new JRadioButton("男",true);
      women_jrb = new JRadioButton("女");
      man_jrb.setFont(font);
      women_jrb.setFont(font);
      man_jrb.addItemListener(this);
      women_jrb.addItemListener(this);
      g = new ButtonGroup();
      g.add(man_jrb);
      g.add(women_jrb);

      userName_TF = new JTextField(15);
      userPassword_TF =new JTextField(15);
      userPassConfirm_TF = new JTextField(15);
      userPhone_TF = new JTextField(11);

      register_btn =new JButton("注册");
      cancel_btn = new JButton("取消");
      register_btn.setFont(font);
      cancel_btn.setFont(font);
      register_btn.addActionListener(this);
      cancel_btn.addActionListener(this);

      this.setLayout(new GridLayout(6,1));
      jp[0].add(lb1);
      jp[0].add(userName_TF);
      jp[1].add(lb2);
      jp[1].add(userPassword_TF);
      jp[2].add(lb3);
      jp[2].add(userPassConfirm_TF);
      jp[3].add(lb5);
      jp[3].add(man_jrb);
      jp[3].add(women_jrb);
      jp[4].add(lb4);
      jp[4].add(userPhone_TF);
      jp[5].add(register_btn);
      jp[5].add(cancel_btn);

      for(int i=0;i<jp.length;i++){
         this.add(jp[i]);
      }

      this.setTitle("注册");
      this.setSize(300, 400);
      this.setLocationRelativeTo(null);
      this.setVisible(true);

   }

   @Override
   public void actionPerformed(ActionEvent e) {
      // TODO Auto-generated method stub
      if(e.getActionCommand()=="注册"){
         UserInfo info =new UserInfo();
         if(!userName_TF.getText().isEmpty()){
            if(!info.IsHaveUsername(userName_TF.getText())){
               userName=userName_TF.getText();
            }else{
               JOptionPane.showMessageDialog(null, "此用户名已占用,请重新输入", "注册提示", JOptionPane.WARNING_MESSAGE);
               return;
            }
         }else{
            JOptionPane.showMessageDialog(null, "用户名为空,请重新输入", "注册提示", JOptionPane.WARNING_MESSAGE);
            return;
         }
         if(userPassword_TF.getText().equals(userPassConfirm_TF.getText())&&userPassword_TF.getText().length()>5){
            userPassword=userPassword_TF.getText();
         }
         else{
            JOptionPane.showMessageDialog(null, "两次密码不正确或密码少于6位,请重新输入", "注册提示", JOptionPane.WARNING_MESSAGE);
            return;
         }
         if(IsPhoneVeritify(userPhone_TF.getText())){
            userPhone=userPhone_TF.getText();
         }else{
            JOptionPane.showMessageDialog(null, "请输入正确的手机号码", "注册提示", JOptionPane.WARNING_MESSAGE);
            return;
         }

         System.out.println(userName+"\t"+userPassword+"\t"+userPhone+"\t"+userSex+"\t");
         info.Register(userName, userPassword, userPhone, userSex);
         JOptionPane.showMessageDialog(null, "注册成功", "注册提示", JOptionPane.WARNING_MESSAGE);
         this.dispose();
      }
      else if(e.getActionCommand()=="取消"){
         this.dispose();
      }
   }

   public static void main(String[] args) {
      try
      {
         BeautyEyeLNFHelper.frameBorderStyle=BeautyEyeLNFHelper.FrameBorderStyle.translucencyAppleLike;
         org.jb2011.lnf.beautyeye.BeautyEyeLNFHelper.launchBeautyEyeLNF();
         UIManager.put("RootPane.setupButtonVisible", false);
      }
      catch(Exception e)
      {
         //TODO exception
      }
      NewTrainUI rUI =new NewTrainUI();
   }

   @Override
   public void itemStateChanged(ItemEvent e) {
      // TODO Auto-generated method stub
      if(e.getItemSelectable()==man_jrb){
         userSex="男";
      }else {
         userSex="女";
      }
   }

   public boolean IsPhoneVeritify(String phone){
      String regExp = "^[1]([3][0-9]{1}|55|59|58|88|89)[0-9]{8}$";
      Pattern p = Pattern.compile(regExp);
      Matcher m = p.matcher(phone);
      return m.find();
   }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).