这部分实现对操作员或管理员张好的密码进行修改的功能,用户需要提供用户名,原密码、新密码和去人新密码,界面设计如图4-4
图4-4
操作员密码修改由用户名、原密码和新密码构成,在操作员输入用户名,密码和新密码后,系统首先验证输入字符的有效性,然后调用数据库查看此用户名是否存在或密码是否正确,然后再执行更新过程。
输入:用户名、愿密码和确认新密码。
处理:
1)效验字符的有效性。要检验用户是否满足输入的要求,即检验用户名和密码文本框是否,若为空,则提示用户输入用户名和密码。
2)检验用户名是否存在或密码是否正确,即是否存在用户输入的用户名,并且密码是否正确。
2)检验新密码与确认新密码是否一致,防止用户误输入密码。
4)执行更新过程。
5)关闭本窗体。
输出:更新成功或失败信息
package Manager;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class userUpdate extends JFrame {
  ResultSet rs;    //定义结果集
  private DBManager db =new DBManager();//定义数据库操作对象
  XYLayout xYLayout1 = new XYLayout();
  JPasswordField jPasswordnew = new JPasswordField();
  JLabel jLabel2 = new JLabel();
  JButton jButtonCancel = new JButton();
  JLabel jLabel1 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JTextField jTextFieldusername = new JTextField();
  JButton jButtonOK = new JButton();
  JPasswordField jPasswordold = new JPasswordField();
  JPasswordField jPasswordnewconfirm = new JPasswordField();
  JLabel jLabel4 = new JLabel();
  public userUpdate() {
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    userUpdate userUpdate = new userUpdate();
  }
  private void jbInit() throws Exception {
    jPasswordold.setText("");
    jButtonOK.setFont(new java.awt.Font("Dialog", 0, 16));
    jButtonOK.addMouseListener(new userUpdate_jButtonOK_mouseAdapter(this));
    jButtonOK.setText("更新");
     jTextFieldusername.setFont(new java.awt.Font("Dialog", 0, 16));
    jTextFieldusername.setText("");
    jLabel3.setText("新密码");
    jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setText("用户名");
    jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16));
     jButtonCancel.setText("取消");
    jButtonCancel.addMouseListener(new userUpdate_jButtonCancel_mouseAdapter(this));
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel2.setText("原密码");
    jPasswordnew.setText("");
    jPasswordnew.setFont(new java.awt.Font("Dialog", 0, 16));
    xYLayout1.setWidth(452);
    xYLayout1.setHeight(326);
    this.getContentPane().setLayout(xYLayout1);
    jPasswordnewconfirm.setFont(new java.awt.Font("Dialog", 0, 16));
    jPasswordnewconfirm.setText("");
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel4.setText("确认新密码");
    this.setTitle("修改密码");
    this.getContentPane().add(jTextFieldusername, new XYConstraints(257, 31, 111, 38));
    this.getContentPane().add(jPasswordnew, new XYConstraints(257, 147, 114, 31));
    this.getContentPane().add(jLabel2, new XYConstraints(107, 98, 80, 34));
    this.getContentPane().add(jLabel1, new XYConstraints(106, 32, 99, 34));
    this.getContentPane().add(jPasswordold,  new XYConstraints(258, 94, 111, 34));
    this.getContentPane().add(jPasswordnewconfirm,  new XYConstraints(255, 205, 119, 31));
this.getContentPane().add(jButtonOK, new XYConstraints(125, 若图片无法显示请联系QQ752018766,本论文免费,转发请注明源于www.751com.cn
  void jButtonCancel_mouseClicked(MouseEvent e) {
        this.dispose();
  }
  void jButtonOK_mouseClicked(MouseEvent e) {
         String strSQL ;
         //校验两次输入的新密码是否一致
         if(!jPasswordnewconfirm.getText().trim().equals(jPasswordnew.getText().trim()))
                 {JOptionPane.showMessageDialog(null,"两次输入的新密码不一致!");
                  return;
            }
  //生成sql语句,用户名和密码从相应文本框取得
strSQL="select * from user where Username='"+jTextFieldusername.getText().trim() +"' and Password='"+jPasswordold.getText().trim()+"'";
         //由DBManager对象执行查询过程
         rs=db.getResult(strSQL) ;
         //判断结果集是否为空
          boolean  isexist=false;
           try {
             isexist = rs.first();
               }
           catch (SQLException ex1) {
              JOptionPane.showMessageDialog(null,ex1.toString() );
                   }
//若为空,则说明用户名不存在或密码不正确,弹出警告信息,并设定主窗体权限为无
             if(!isexist)
{JOptionPane.showMessageDialog(null,"用户名不存在,或原密码不正确!");
   return;
 }
//若不为空,则说明用户名存在且密码正确,执行更新过程
   (null,"成功更新!"); }
else
  { JOptionPane.showMessageDialog(null," 更新失败,请重新操作!");      }
                }
  }
}
若图片无法显示请联系QQ752018766,本论文免费,转发请注明源于www.751com.cn
}
class userUpdate_jButtonOK_mouseAdapter extends java.awt.event.MouseAdapter {
  userUpdate adaptee;
  userUpdate_jButtonOK_mouseAdapter(userUpdate adaptee) {
    this.adaptee = adaptee;
  }
public void mouseClicked(MouseEvent e) {
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>