Registration.java~26~
上传用户:liming9091
上传日期:2014-10-27
资源大小:3376k
文件大小:5k
源码类别:

Java编程

开发平台:

Java

  1. package uml_gaokai;
  2. import java.awt.*;
  3. import javax.swing.*;
  4. import com.borland.jbcl.layout.*;
  5. import java.awt.event.*;
  6. import com.borland.dx.sql.dataset.*;
  7. import java.sql.*;
  8. /**
  9.  * <p>Title: </p>
  10.  * <p>Description: </p>
  11.  * <p>Copyright: Copyright (c) 2003</p>
  12.  * <p>Company: </p>
  13.  * @author unascribed
  14.  * @version 1.0
  15.  */
  16. public class Registration extends JDialog implements ActionListener {
  17.   private JPanel panel1 = new JPanel();
  18.   private BorderLayout borderLayout1 = new BorderLayout();
  19.   private JPanel jPanel1 = new JPanel();
  20.   private XYLayout xYLayout1 = new XYLayout();
  21.   private JLabel jLabel1 = new JLabel();
  22.   private JLabel jLabel2 = new JLabel();
  23.   private JLabel jLabel3 = new JLabel();
  24.   private JLabel jLabel4 = new JLabel();
  25.   private JTextField jTextField1 = new JTextField();
  26.   private JTextField jTextField2 = new JTextField();
  27.   private JTextField jTextField3 = new JTextField();
  28.   private JTextField jTextField4 = new JTextField();
  29.   private JLabel jLabel5 = new JLabel();
  30.   private JLabel jLabel6 = new JLabel();
  31.   private JLabel jLabel7 = new JLabel();
  32.   private JTextField jTextField5 = new JTextField();
  33.   private JPasswordField jTextField6 = new JPasswordField();
  34.   private JPasswordField jTextField7 = new JPasswordField();
  35.   private JButton jButton1 = new JButton();
  36.   private JButton jButton2 = new JButton();
  37.   public Registration(Frame frame, String title, boolean modal) {
  38.     super(frame, title, modal);
  39.     try {
  40.       jbInit();
  41.       pack();
  42.     }
  43.     catch(Exception ex) {
  44.       ex.printStackTrace();
  45.     }
  46.   }
  47.   public Registration() {
  48.     this(null, "", false);
  49.   }
  50.   private void jbInit() throws Exception {
  51.     panel1.setLayout(borderLayout1);
  52.     jPanel1.setLayout(xYLayout1);
  53.     jLabel1.setText("姓名");
  54.     jLabel2.setText("年龄");
  55.     jLabel3.setText("性别");
  56.     jLabel4.setText("类别");
  57.     jLabel5.setText("请输入密码");
  58.     jLabel6.setText("请再输一遍");
  59.     jLabel7.setText("家庭住址");
  60.     jButton1.setText("确定");
  61.     jButton1.addActionListener(new java.awt.event.ActionListener() {
  62.       public void actionPerformed(ActionEvent e) {
  63.         jButton1_actionPerformed(e);
  64.       }
  65.     });
  66.     jButton2.setText("取消");
  67.     jButton2.addActionListener(new java.awt.event.ActionListener() {
  68.       public void actionPerformed(ActionEvent e) {
  69.         jButton2_actionPerformed(e);
  70.       }
  71.     });
  72.     jPanel1.setPreferredSize(new Dimension(400, 300));
  73.     getContentPane().add(panel1);
  74.     panel1.add(jPanel1, BorderLayout.CENTER);
  75.     jPanel1.add(jTextField1,  new XYConstraints(80, 31, 76, 25));
  76.     jPanel1.add(jTextField2,   new XYConstraints(79, 76, 78, 23));
  77.     jPanel1.add(jTextField3,  new XYConstraints(79, 119, 77, 25));
  78.     jPanel1.add(jTextField4,  new XYConstraints(78, 159, 77, 26));
  79.     jPanel1.add(jLabel4, new XYConstraints(26, 158, 42, 28));
  80.     jPanel1.add(jLabel3, new XYConstraints(28, 118, 39, 28));
  81.     jPanel1.add(jLabel2, new XYConstraints(28, 76, 48, 26));
  82.     jPanel1.add(jLabel1,  new XYConstraints(31, 35, 41, 27));
  83.     jPanel1.add(jLabel7, new XYConstraints(185, 30, 49, 25));
  84.     jPanel1.add(jTextField5,     new XYConstraints(258, 35, 120, -1));
  85.     jPanel1.add(jLabel5,  new XYConstraints(185, 78, 78, 23));
  86.     jPanel1.add(jLabel6,    new XYConstraints(185, 116, 73, 23));
  87.     jPanel1.add(jTextField7,    new XYConstraints(258, 119, 121, 23));
  88.     jPanel1.add(jTextField6,  new XYConstraints(258, 79, 119, 24));
  89.     jPanel1.add(jButton1,   new XYConstraints(197, 194, 80, 26));
  90.     jPanel1.add(jButton2,    new XYConstraints(296, 194, 82, 26));
  91.   }
  92.   public void actionPerformed(ActionEvent ee){
  93.   }
  94.   void jButton1_actionPerformed(ActionEvent e) {
  95.     String userName = String.valueOf(jTextField1.getText()) ;
  96.     int userAge = Integer.parseInt(String.valueOf(jTextField2.getText())) ;
  97.     String userGender = String.valueOf(jTextField3.getText()) ;
  98.     String userAuthority = String.valueOf(jTextField4.getText()) ;
  99.     String userAddress = String.valueOf(jTextField5.getText()) ;
  100.     String userPassword = String.valueOf(jTextField6.getPassword()) ;
  101.     String testPassword = String.valueOf(jTextField7.getPassword()) ;
  102.     if(userPassword.equals(testPassword)){
  103.       try{
  104.         Database database1 = new Database();
  105.         database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:odbc:gaokaiSQL", "sa", "", false, "sun.jdbc.odbc.JdbcOdbcDriver"));
  106.         Statement sql1 = database1.createStatement() ;
  107.         sql1.executeUpdate("INSERT INTO [UML_CS].[dbo].[user](userName, userAge , userGender, userAuthority , userAddress , userPassword) VALUES('"+userName+"' , '"+userAge+"' , '"+userGender+"' , '"+userAuthority+"' , '"+userAddress+"','"+userPassword+"')") ;
  108.         JOptionPane.showMessageDialog(null,"注册成功,请重新登陆","",JOptionPane.DEFAULT_OPTION);
  109.         cancel();
  110.       }
  111.       catch(SQLException www){www.printStackTrace();}
  112.     }
  113.     else{
  114.       JOptionPane.showMessageDialog(null,"您输入的密码前后不符,请重新输入","",JOptionPane.DEFAULT_OPTION);
  115.     }
  116.   }
  117.   public void cancel(){
  118.     dispose() ;
  119.   }
  120.   void jButton2_actionPerformed(ActionEvent e) {
  121.     cancel() ;
  122.   }
  123. }