d_epassword.java

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

JAVA
186
字号
/*
 * D_epassword.java
 *
 * Created on 2007年6月24日, 上午8:44
 */

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

public class D_epassword extends javax.swing.JFrame {
    
    /** Creates new form D_epassword */
    public D_epassword() {
        initComponents();
        con=connect.getcon();
        stmt=connect.getstmt();
        this.setTitle("修改密码");
        this.setBounds(300,250,350,300);
        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();
        B_change = new javax.swing.JButton();
        B_cancel = new javax.swing.JButton();
        PW_old = new javax.swing.JPasswordField();
        PW_new = new javax.swing.JPasswordField();
        PW_con = new javax.swing.JPasswordField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        jLabel1.setText("\u8bf7\u8f93\u5165\u65e7\u5bc6\u7801\uff1a");

        jLabel2.setText("\u8bf7\u8f93\u5165\u65b0\u5bc6\u7801\uff1a");

        jLabel3.setText("\u786e\u8ba4\u65b0\u5bc6\u7801\uff1a");

        B_change.setText("\u4fee\u6539");
        B_change.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_changeActionPerformed(evt);
            }
        });

        B_cancel.setText("\u53d6\u6d88");
        B_cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                B_cancelActionPerformed(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()
                .addContainerGap(31, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel2)
                    .add(jLabel1)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                        .add(B_change)
                        .add(jLabel3)))
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(0, 0, 0)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, PW_new, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                            .add(PW_old, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, PW_con, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 103, Short.MAX_VALUE)))
                    .add(layout.createSequentialGroup()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(B_cancel)))
                .add(58, 58, 58))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(29, 29, 29)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(PW_old, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(23, 23, 23)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel2)
                    .add(PW_new, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel3)
                    .add(PW_con, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(33, 33, 33)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(B_change)
                    .add(B_cancel))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

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

    private void B_changeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_B_changeActionPerformed
// TODO 将在此处添加您的处理代码:
        try{
            ResultSet rs=stmt.executeQuery("select 用户名,密码,权限 from 用户表");
            while(rs.next()) {
                String name1,name2,pwold,pwnew,pwcon,level,pw1,pw2;
                char ch[];
                name1=loginuser.getusername().trim();
                name2=(String)rs.getString(1).trim();
              if(name1.equals(name2))
              {
                    ch=PW_old.getPassword();
                    pw1=new String(ch).trim();
                    pw2=rs.getString(2).trim();
                    if(pw1.equals(pw2))
                    {
                        ch=PW_new.getPassword();
                        pwnew=new String(ch);
                        pwnew=pwnew.trim();
                        ch=PW_con.getPassword();
                        pwcon=new String(ch);
                        pwcon=pwcon.trim();
                        if(pwcon.equals(pwnew))
                        {
                            PreparedStatement sql=con.prepareStatement("update 用户表 set 密码=? where 用户名=?");
                            sql.setString(1,pwcon);
                            sql.setString(2,name1);
                            sql.executeUpdate();
                            JOptionPane.showMessageDialog(null,"密码修改成功");
                            this.setVisible(false);
                        }
                    
                }
                    else 
                    {
                        JOptionPane.showMessageDialog(null,"密码错误!");
                        this.setVisible(false);
                        return;
                    }
            }
        }
            rs.close();
        }
        catch(Exception ee)
         {
 ee.printStackTrace();
}
    }//GEN-LAST:event_B_changeActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new D_epassword().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton B_cancel;
    private javax.swing.JButton B_change;
    private javax.swing.JPasswordField PW_con;
    private javax.swing.JPasswordField PW_new;
    private javax.swing.JPasswordField PW_old;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // 变量声明结束//GEN-END:variables
    private Connection con;
    private Statement stmt;
}

⌨️ 快捷键说明

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