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

📄 enroll.java~13~

📁 一款高校科研管理系统
💻 JAVA~13~
字号:
package scince;

import java.awt.*;

import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Enroll extends JDialog {
    JPanel panel1 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JLabel jLabel1 = new JLabel();
    JTextField jTextField1 = new JTextField();
    JLabel jLabel2 = new JLabel();
    JPasswordField jPasswordField1 = new JPasswordField();
    JLabel jLabel3 = new JLabel();
    JPasswordField jPasswordField2 = new JPasswordField();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel5 = new JLabel();
    JButton jButton3 = new JButton();
    public Enroll(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            pack();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public Enroll() {
        this(new Frame(), "Enroll", false);
    }

    private void jbInit() throws Exception {
        panel1.setLayout(null);
        this.getContentPane().setLayout(null);
        this.setDefaultCloseOperation(javax.swing.WindowConstants.
                                      DO_NOTHING_ON_CLOSE);
        jButton1.setBounds(new Rectangle(56, 232, 90, 35));
        jButton1.setText("确定");
        jButton1.addActionListener(new Enroll_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(163, 232, 89, 35));
        jButton2.setText("重置");
        jButton2.addActionListener(new Enroll_jButton2_actionAdapter(this));
        jLabel1.setText("新用户名:");
        jLabel1.setBounds(new Rectangle(36, 17, 92, 34));
        jTextField1.setBounds(new Rectangle(136, 22, 86, 29));
        jLabel2.setText("密码");
        jLabel2.setBounds(new Rectangle(46, 80, 52, 24));
        jPasswordField1.setBounds(new Rectangle(138, 77, 82, 30));
        jLabel3.setText("重复确认密码");
        jLabel3.setBounds(new Rectangle(22, 154, 73, 26));
        jPasswordField2.setBounds(new Rectangle(141, 147, 82, 33));
        jLabel4.setText("字母或数字20位以内");
        jLabel4.setBounds(new Rectangle(245, 25, 128, 24));
        jLabel5.setText("字母或数字20位以内");
        jLabel5.setBounds(new Rectangle(247, 78, 113, 31));
        jButton3.setBounds(new Rectangle(274, 233, 88, 37));
        jButton3.setText("取消退出");
        jButton3.addActionListener(new Enroll_jButton3_actionAdapter(this));
        panel1.setBackground(Color.blue);
        panel1.add(jButton1);
        panel1.add(jTextField1);
        panel1.add(jPasswordField1);
        panel1.add(jLabel3);
        panel1.add(jLabel4);
        panel1.add(jLabel5);
        panel1.add(jButton2);
        panel1.add(jButton3);
        panel1.add(jPasswordField2);
        panel1.add(jLabel2);
        panel1.add(jLabel1);
        this.getContentPane().add(panel1, null);
        panel1.setBounds(new Rectangle( -2, 0, 409, 336));
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        Connection con;
        Statement sql;
        ResultSet rs;
        String queryString;
        String user;
        String password;
        String password1;
        user = jTextField1.getText().trim();
        password = jPasswordField1.getText();
        password1 = jPasswordField2.getText();
        queryString = "select * from 用户 where 用户名='" + user + "'";
        //判断用户名及密码是否为空
        if(user.equals("")||password.equals("")||password1.equals(""))
            JOptionPane.showMessageDialog(null, "请输入用户名和密码!", "用户注册对话框",
                                          JOptionPane.WARNING_MESSAGE);
        if(!user.equals("")&& !password.equals("")&& !password1.equals(""))
        {
            //检查两个密码是否一致
            if(!password.endsWith(password1))
            { JOptionPane.showMessageDialog(null, "密码不一致!", "用户注册对话框",
                                          JOptionPane.WARNING_MESSAGE);
                jPasswordField1.setText("");
                jPasswordField2.setText("");
            }
            //检查用户名是否已经存在
            else
            {
                try {
           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       } catch (java.lang.ClassNotFoundException ee) {
           System.err.print("class not find!");
           System.err.println(ee.getMessage());
       }
       try {
           con = DriverManager.getConnection("jdbc:odbc:scince", "", "");
            sql = con.createStatement();
            rs = sql.executeQuery(queryString);
            if(rs.next())
            {
                JOptionPane.showMessageDialog(null, "用户名已经存在!", "用户注册对话框",
                                          JOptionPane.WARNING_MESSAGE);
                  jTextField1.setText("");
                  jPasswordField1.setText("");
                  jPasswordField2.setText("");

              }
              else {
                  queryString="Insert into  用户 values('"+user+"',"+"'"+password+"')";
                  sql.executeUpdate(queryString);
                  JOptionPane.showMessageDialog(null, "用户申请成功!", "用户注册对话框",
                                          JOptionPane.INFORMATION_MESSAGE);
              }

       }catch(SQLException ex){};

            }
        }

         //this.dispose();
    }

    public void jButton2_actionPerformed(ActionEvent e) {
  jTextField1.setText("");
  jPasswordField1.setText("");
  jPasswordField2.setText("");
    }

    public void jButton3_actionPerformed(ActionEvent e) {
          this.dispose();
    }
}


class Enroll_jButton3_actionAdapter implements ActionListener {
    private Enroll adaptee;
    Enroll_jButton3_actionAdapter(Enroll adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton3_actionPerformed(e);
    }
}


class Enroll_jButton2_actionAdapter implements ActionListener {
    private Enroll adaptee;
    Enroll_jButton2_actionAdapter(Enroll adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}


class Enroll_jButton1_actionAdapter implements ActionListener {
    private Enroll adaptee;
    Enroll_jButton1_actionAdapter(Enroll adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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