d_adduser.java

来自「图书管理系统」· Java 代码 · 共 189 行

JAVA
189
字号
/*
 * D_adduser.java
 *
 * Created on 2007年6月24日, 下午10:46
 */

package 图书管理系统;
import javax.swing.*;
import java.sql.*;

public class D_adduser extends javax.swing.JFrame {
    
    /** Creates new form D_adduser */
    public D_adduser() {
        initComponents();
        con=connect.getcon();
        stmt=connect.getstmt();
        this.setTitle("添加用户");
        this.setBounds(300,250,350,350);
        this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        T_username = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        T_qx = new javax.swing.JTextField();
        PW_userpw = new javax.swing.JPasswordField();
        PW_conpw = new javax.swing.JPasswordField();
        B_adduser = new javax.swing.JButton();
        B_addcancel = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8bf7\u8f93\u5165\u60a8\u6240\u8981\u6dfb\u52a0\u7684\u7528\u6237\u4fe1\u606f");

        jLabel2.setText("\u7528\u6237\u540d:");

        jLabel3.setText("\u7528\u6237\u5bc6\u7801:");

        jLabel4.setText("\u7528\u6237\u6743\u9650:");

        jLabel5.setText("\u786e\u8ba4\u5bc6\u7801:");

        B_adduser.setText("\u6dfb\u52a0");
        B_adduser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_adduserActionPerformed(evt);
            }
        });

        B_addcancel.setText("\u53d6\u6d88");
        B_addcancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_addcancelActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jLabel1))
                    .add(layout.createSequentialGroup()
                        .add(65, 65, 65)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel4)
                            .add(jLabel3)
                            .add(jLabel5)
                            .add(jLabel2)
                            .add(org.jdesktop.layout.GroupLayout.TRAILING, B_adduser))
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(layout.createSequentialGroup()
                                .add(25, 25, 25)
                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                                    .add(T_qx, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .add(PW_conpw, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .add(PW_userpw, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)
                                    .add(T_username, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 78, Short.MAX_VALUE)))
                            .add(layout.createSequentialGroup()
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(B_addcancel)))))
                .add(83, 83, 83))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(T_username, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(14, 14, 14)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(PW_userpw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(PW_conpw, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 19, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(24, 24, 24)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(T_qx, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(25, 25, 25)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(B_adduser)
                    .add(B_addcancel))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void B_addcancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_addcancelActionPerformed
// TODO 将在此处添加您的处理代码:
        this.setVisible(false);
    }//GEN-LAST:event_B_addcancelActionPerformed

    private void B_adduserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_adduserActionPerformed
// TODO 将在此处添加您的处理代码:
         try{
            boolean sign=false;
          char[] ch;
          String pw1,pw2;
          pw1=new String(PW_userpw.getPassword());
          pw2=new String(PW_conpw.getPassword());
          pw1=pw1.trim();
          pw2=pw2.trim();
          if(!pw1.equals(pw2))
          {
             JOptionPane.showMessageDialog(null,"密码匹配错误");
             return;
          }
         
            PreparedStatement sql=con.prepareStatement("insert into 用户表 values(?,?,?)");
                sql.setString(1,T_username.getText().trim());
                sql.setString(2,pw1);
                sql.setString(3,T_qx.getText().trim());
                sql.executeUpdate();
                JOptionPane.showMessageDialog(null,"用户添加成功");
                this.setVisible(false);
         }
        catch(Exception ee)
         {
 ee.printStackTrace();
     }
    }//GEN-LAST:event_B_adduserActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new D_adduser().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton B_addcancel;
    private javax.swing.JButton B_adduser;
    private javax.swing.JPasswordField PW_conpw;
    private javax.swing.JPasswordField PW_userpw;
    private javax.swing.JTextField T_qx;
    private javax.swing.JTextField T_username;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    // 变量声明结束//GEN-END:variables
    private Connection con;
    private Statement stmt;
}

⌨️ 快捷键说明

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