⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 personauth.java~268~

📁 基于java 的号码生成器,在Jbuilder 2005中调试
💻 JAVA~268~
字号:
package personauth;

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.util.Vector;
import java.io.*;
import java.awt.Rectangle;

public class PersonAuth extends JFrame implements ItemListener,ActionListener {

    JLabel L_Province = new JLabel();
    JLabel L_Town = new JLabel();
    JComboBox JC_Province;
    static JComboBox JC_town = new JComboBox();
    static Vector code = new Vector();
    static Vector region = new Vector();
    JComboBox JC_sex = new JComboBox();
    JLabel L_sex = new JLabel();
    JLabel L_birthday = new JLabel();
    static JTextField T_year = new JTextField("1982");
    JLabel L_year = new JLabel();
    JLabel L_month = new JLabel();
    static JComboBox JC_month = new JComboBox();
    static JComboBox JC_data = new JComboBox();
    JLabel L_day = new JLabel();
    JButton JB_Create = new JButton();
    JButton JB_exit = new JButton();
    JTextField T_pesron_id = new JTextField();
    JButton JB_validate = new JButton();
    JButton JB_about = new JButton();
    static int sex=1;// 1男性 2女性
    static int month=1;
    static int data=1;
    static String town="市辖区";
    static int[] wi={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    static char[] vi={'1','0','X','9','8','7','6','5','4','3','2'};
    public PersonAuth() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        this.setResizable(false);
        setTitle("18位身份证号码生成器V1.0");
        JC_Province = new JComboBox();
        JC_Province.addItem("北京市");
        JC_Province.addItem("天津市");
        JC_Province.addItem("河北省");
        JC_Province.addItem("山西省");
        JC_Province.addItem("内蒙古自治区");
        JC_Province.addItem("辽宁省");
        JC_Province.addItem("吉林省");
        JC_Province.addItem("黑龙江省");
        JC_Province.addItem("上海市");
        JC_Province.addItem("江苏省");
        JC_Province.addItem("浙江省");
        JC_Province.addItem("安徽省");
        JC_Province.addItem("福建省");
        JC_Province.addItem("江西省");
        JC_Province.addItem("山东省");
        JC_Province.addItem("河南省");
        JC_Province.addItem("湖北省");
        JC_Province.addItem("湖南省");
        JC_Province.addItem("广东省");
        JC_Province.addItem("广西壮族自治区");
        JC_Province.addItem("海南省");
        JC_Province.addItem("重庆市");
        JC_Province.addItem("四川省");
        JC_Province.addItem("贵州省");
        JC_Province.addItem("云南省");
        JC_Province.addItem("西藏自治区");
        JC_Province.addItem("陕西省");
        JC_Province.addItem("甘肃省");
        JC_Province.addItem("青海省");
        JC_Province.addItem("宁夏回族自治区");
        JC_Province.addItem("新疆维吾尔自治区");
        JC_Province.addItemListener(this);
        L_Province.setText("省级行政机构");
        L_Province.setBounds(new Rectangle(11, 21, 82, 15));
        Init_Info();
        Update_town("北京市");
        JC_Province.setBounds(new Rectangle(14, 47, 69, 23));
        JC_town.setBounds(new Rectangle(102, 47, 70, 23));
        JC_town.addItemListener(this);
        JC_sex.setBounds(new Rectangle(204, 46, 42, 23));
        JC_sex.addItem("男");
        JC_sex.addItem("女");
        JC_sex.addItemListener(this);
        L_sex.setText("性别");
        L_sex.setBounds(new Rectangle(205, 23, 42, 23));
        L_birthday.setText("设置出生日期");
        L_birthday.setBounds(new Rectangle(12, 92, 127, 15));
        T_year.setBounds(new Rectangle(14, 118, 70, 23));
       // T_year.setColumns(4);
        L_year.setText("年");
        L_year.setBounds(new Rectangle(95, 123, 21, 15));
        L_month.setText("月");
        L_month.setBounds(new Rectangle(175, 124, 24, 15));
        JC_month.setBounds(new Rectangle(119, 118, 42, 23));
        for(int num=1;num<=12;num++)
             JC_month.addItem(num);
        JC_month.addItemListener(this);
        JC_data.setBounds(new Rectangle(205, 118, 42, 23));
        for(int num=1;num<=31;num++)
             JC_data.addItem(num);
        JC_data.addItemListener(this);
        L_day.setText("日");
        L_day.setBounds(new Rectangle(254, 124, 22, 15));
        JB_Create.setBounds(new Rectangle(13, 163, 62, 23));
        JB_Create.setText("计算");
        JB_Create.addActionListener(this);
        JB_exit.setBounds(new Rectangle(195, 162, 64, 23));
        JB_exit.setText("退出");
        JB_exit.addActionListener(this);
        T_pesron_id.setBounds(new Rectangle(113, 208, 153, 20));
        JB_validate.setBounds(new Rectangle(13, 205, 81, 23));
        JB_validate.setText("验证身份证");
        JB_validate.addActionListener(this);
        JB_about.setBounds(new Rectangle(106, 163, 64, 23));
        JB_about.setText("关于");
        JB_about.addActionListener(this);
        this.getContentPane().add(L_Province);
        this.getContentPane().add(JC_Province);
        this.getContentPane().add(L_birthday);
        this.getContentPane().add(T_year);
        this.getContentPane().add(L_year);
        this.getContentPane().add(L_day);
        this.getContentPane().add(L_month);
        this.getContentPane().add(L_Town);
        this.getContentPane().add(JC_town);
        this.getContentPane().add(L_sex);
        this.getContentPane().add(JC_sex);
        this.getContentPane().add(JC_data);
        this.getContentPane().add(JC_month);
        this.getContentPane().add(JB_Create);
        this.getContentPane().add(T_pesron_id);
        this.getContentPane().add(JB_exit);
        this.getContentPane().add(JB_about);
        this.getContentPane().add(JB_validate);
        L_Town.setText("下级行政机构");
        L_Town.setBounds(new Rectangle(99, 22, 84, 15));
        setSize(300,280);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = screenSize.width;
        int screenHeight = screenSize.height;
        Dimension frameSize=this.getSize();
        int x=(screenWidth-frameSize.width)/2;
        int y=(screenHeight-frameSize.height)/2;
        this.setLocation(x,y);
        this.setVisible(true);
    }

    public void itemStateChanged(ItemEvent e){

        if(e.getSource()==JC_Province)
        {
            System.out.println("Province="+JC_Province.getSelectedItem());
            JC_town.removeAllItems();
            Update_town(JC_Province.getSelectedItem());
        }
        if(e.getSource()==JC_town)
        {
          System.out.println("town="+JC_town.getSelectedItem());
          town=(String)JC_town.getSelectedItem();
        }
        if(e.getSource()==JC_sex)
        {
           if(((String)JC_sex.getSelectedItem()).compareTo("男")==0)
                sex=1;
           if(((String)JC_sex.getSelectedItem()).compareTo("女")==0)
                sex=2;
          System.out.println("sex="+sex);
         }
         if(e.getSource()==JC_month)
         {
           month=((Integer)JC_month.getSelectedItem()).intValue();
           System.out.println("month="+month);
         }
         if(e.getSource()==JC_data)
        {
           data=((Integer)JC_data.getSelectedItem()).intValue();
           System.out.println("data="+data);
        }
    }

    public void actionPerformed(ActionEvent e){

        if(e.getSource()==JB_Create)
        {
             if(Validate_year(T_year.getText())==false )
                 JOptionPane.showMessageDialog(this,
                                          "年份输入错误",
                                          "验证分析",
                                          JOptionPane.INFORMATION_MESSAGE);
             else
             {
                 String res;
                 int i = 1;
                 if (sex == 1)
                     i = 1;
                 if (sex == 2)
                     i = 0;
                 for (; i < 1000; ) {
                     res = assembled_Info();
                     if (i >= 0 && i < 10) {
                         res = res + "00" + i;
                     }
                     if (i >= 10 && i < 100) {
                         res = res + "0" + i;
                     }
                     if (i >= 100 && i < 1000) {
                         res = res + i;
                     }
                     i += 2;
                     System.out.println(CreatePersonID(res));
                 }
              }
        }
        if(e.getSource()==JB_exit)
        {
            System.exit(1);
        }
        if(e.getSource()==JB_validate)
        {
             if(Validate_True(T_pesron_id.getText())==true)
             {
                 JOptionPane.showMessageDialog(this,
                                               Explain_ID(T_pesron_id.getText()),
                                               "分析结果",
                                               JOptionPane.INFORMATION_MESSAGE);
             }else
             {
              JOptionPane.showMessageDialog(this,
                                            "错误的身份证号码",
                                            "分析结果",
                                            JOptionPane.ERROR_MESSAGE);
             }
        }
        if(e.getSource()==JB_about)
        {
            //new  Dialog_about();
            JOptionPane.showMessageDialog(this,"狗狗&猪猪工作室@CopyRight","关于我们",JOptionPane.INFORMATION_MESSAGE);
        }
    }

    public static void Init_Info() throws IOException{
        FileInputStream fin = new FileInputStream("info.txt");
        InputStreamReader read = new InputStreamReader(fin, "gbk");
        BufferedReader reader = new BufferedReader(read);
        String line;
        while ((line = reader.readLine()) != null) {
            if (line.length() == 0) {
                code.add("flag");
                region.add("flag");
            } else {
                code.add(line.substring(1, 7));
                region.add(line.substring(8));
            }
        }
    }

    public static void Update_town(Object ob)
    {
         String temp=(String)ob;
         String temp1="";
         int findflag=0;
         int endflag=0;
         int first=0;
         for(int num=0;num<region.size();num++)
         {
            temp1 = (String) region.get(num);
            //System.out.println(temp1);
            if(temp.compareTo(temp1)==0)
            {
                 findflag=1;
                 first=1;
            }
            if(findflag==1)
            {
                 if(((String)region.get(num)).compareTo("flag")==0)
                 {
                  endflag=1;
                  break;
                 }
            }
            if(findflag==1&&endflag==0){
                // System.out.println(region.get(num));
                if(first==1)
                    first=2;
                else
                   JC_town.addItem((String)region.get(num));
            }
         }
      }

      public static String assembled_Info()
      {
          String res="";
          String temp="";
          for(int i=0;i<region.size();i++)
          {
              temp = (String) region.get(i);
              if(town.compareTo(temp)==0)
              {
                 // System.out.println(code.get(i));
                  res=(String)code.get(i);
                  break;
              }
          }
          res=res+T_year.getText();
          if(month<10)
              res=res+"0"+month;
          else
              res=res+month;
          if(data<10)
              res=res+"0"+data;
          else
              res=res+data;
         //System.out.println("result="+res);
         return res;
      }
      public static String CreatePersonID(String code)
      {
         int sum=0;
         int mod=0;
         for(int i=0;i<17;i++)
           sum=sum+Character.getNumericValue(code.charAt(i))*wi[i];
         mod=sum%11;
         code+=vi[mod];
         return code;
      }

      public static boolean Validate_True(String code)
      {
          code=code.trim();
          if(code.length()!=18)
               return false;
          int sum=0;
          int mod=0;
          for(int i=0;i<17;i++)
             sum=sum+Character.getNumericValue(code.charAt(i))*wi[i];
          mod=sum%11;
          if(code.charAt(17)==vi[mod])
               return true;
          else
               return false;
      }

      public static String Explain_ID(String str)
      {
         String res = "";
         String temp = "";
         res = Find_Position(str.substring(0, 2) + "0000") +
         Find_Position(str.substring(0, 4) + "00") +
         Find_Position(str.substring(0, 6));
             if (res.length() == 0)
                 return res="";
             else
             {
                 res=res+"\n"+"出生年月:"+
                     str.substring(6,10)+"年"+
                     str.substring(10,12)+"月"+
                     str.substring(12,14)+"日\n性别:";
                if(Integer.parseInt(str.substring(14,17))%2==0)
                     res=res+"女";

                else
                     res=res+"男";
             }
        // System.out.println("res="+res);
           return res;
      }

      public static String Find_Position(String str)
      {
         String res="";
         String temp="";
         for(int i=0;i<code.size();i++)
         {
           temp = (String)code.get(i);
           if(str.compareTo(temp)==0)
           {
             res=(String)region.get(i);
             break;
           }
         }
         return res;
      }

      public static boolean Validate_year(String year)
      {
          boolean res=true;
          if(year.length()!=4)
               res=false;
          else
          {
          if(Character.getNumericValue(year.charAt(0))==0||
             Character.getNumericValue(year.charAt(0))>10||
             Character.getNumericValue(year.charAt(0))<=0)
                          res=false;
          if(Character.getNumericValue(year.charAt(1))>=10||
             Character.getNumericValue(year.charAt(0))<0)
                                res= false;
          if(Character.getNumericValue(year.charAt(2))>=10||
              Character.getNumericValue(year.charAt(0))<0)
                                res= false;
          if(Character.getNumericValue(year.charAt(3))>=10||
             Character.getNumericValue(year.charAt(0))<0)
                                res= false;
          }
          return res;
      }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -