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

📄 userupdate.java

📁 比较完整功能全面的图书管理系统;
💻 JAVA
字号:
package bookmanager;

import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.*;
import java.sql.*;
import java.awt.event.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class userUpdate
    extends JFrame {
  //定义结果集
  ResultSet rs;
//定义数据库操作对象
  private DBManager db = new DBManager();

  XYLayout xYLayout1 = new XYLayout();
  JButton jButtonCancel = new JButton();
  JLabel jLabel2 = new JLabel();
  JButton jButtonOK = new JButton();
  JPasswordField jPasswordold = new JPasswordField();
  JLabel jLabel1 = new JLabel();
  JTextField jTextFieldusername = new JTextField();
  JPasswordField jPasswordnew = new JPasswordField();
  JLabel jLabel3 = new JLabel();
  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 {
    jTextFieldusername.setText("");
    jTextFieldusername.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel1.setText("用户名");
    jLabel1.setFont(new java.awt.Font("Dialog", 0, 16));
    jPasswordold.setText("");
    jButtonOK.setText("更新");
    jButtonOK.addMouseListener(new userUpdate_jButtonOK_mouseAdapter(this));
    jButtonOK.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel2.setText("原密码");
    jLabel2.setFont(new java.awt.Font("Dialog", 0, 16));
    jButtonCancel.setText("取消");
    jButtonCancel.addMouseListener(new userUpdate_jButtonCancel_mouseAdapter(this));
    jButtonCancel.setFont(new java.awt.Font("Dialog", 0, 16));
    this.getContentPane().setLayout(xYLayout1);
    xYLayout1.setWidth(463);
    xYLayout1.setHeight(336);
    jLabel3.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel3.setText("新密码");
    jPasswordnew.setFont(new java.awt.Font("Dialog", 0, 16));
    jPasswordnew.setText("");
    jPasswordnewconfirm.setText("");
    jPasswordnewconfirm.setFont(new java.awt.Font("Dialog", 0, 16));
    jLabel4.setText("确认新密码");
    jLabel4.setFont(new java.awt.Font("Dialog", 0, 16));
    this.setTitle("更改密码");
    this.getContentPane().add(jButtonOK, new XYConstraints(106, 272, 91, 31));
    this.getContentPane().add(jButtonCancel, new XYConstraints(232, 275, 94, 30));
    this.getContentPane().add(jTextFieldusername,
                              new XYConstraints(263, 49, 113, 33));
    this.getContentPane().add(jPasswordold, new XYConstraints(264, 110, 110, 32));
    this.getContentPane().add(jPasswordnew, new XYConstraints(263, 160, 114, 31));
    this.getContentPane().add(jPasswordnewconfirm,
                              new XYConstraints(262, 214, 114, 31));
    this.getContentPane().add(jLabel2, new XYConstraints(92, 104, 80, 34));
    this.getContentPane().add(jLabel4, new XYConstraints(92, 208, 125, 30));
    this.getContentPane().add(jLabel1, new XYConstraints(92, 45, 99, 34));
    this.getContentPane().add(jLabel3, new XYConstraints(90, 156, 62, 30));
  }

  void jButtonCancel_mouseClicked(MouseEvent e) {
    this.dispose();
  }

  void jButtonOK_mouseClicked(MouseEvent e) {
    String strSQL;
    //校验用户名是否为空
    if (jTextFieldusername.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(null, "用户名不许为空!");
      return;
    }
    //校验原密码是否为空
    if (jPasswordold.getText().trim().equals("")) {
      JOptionPane.showMessageDialog(null, "密码不许为空!");
      return;
    }
    //检验用户两次输入的密码是否一致
    if (!jPasswordnewconfirm.getText().trim().equals(jPasswordnew.getText().
        trim())) {
      JOptionPane.showMessageDialog(null, "两次输入的密码不一致!");
      return;
    }
    //检验用户名是否存在
    strSQL = "select * from user where Username='" +
        jTextFieldusername.getText().trim() + "' and Password='" +
        jPasswordold.getText().trim() + "'";
    rs = db.getResult(strSQL);
    boolean isexist = false;
    try {
      isexist = rs.first();
    }
    catch (SQLException ex1) {
    }
    //若用户名不存在,提示警告信息提醒用户从新输入
    if (!isexist)

    {
      JOptionPane.showMessageDialog(null, "用户名不存在,或原密码不正确!");
    }
    //若存在,执行更新操作
    else {
      //生成更新sql语句
      strSQL = "update user set Password='" + jPasswordnew.getText().trim() +
          "' where Username='" + jTextFieldusername.getText().trim() + "'";
      //由数据库操作对象执行数据库操作,并返回操作成功失败的提示信息
      if (db.executeSql(strSQL)) {
        JOptionPane.showMessageDialog(null, "成功更新!");
      }
      else {
        JOptionPane.showMessageDialog(null, " 更新失败,请重新操作!");
      }
    }
  }
}

class userUpdate_jButtonCancel_mouseAdapter
    extends java.awt.event.MouseAdapter {
  userUpdate adaptee;

  userUpdate_jButtonCancel_mouseAdapter(userUpdate adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButtonCancel_mouseClicked(e);
  }
}

class userUpdate_jButtonOK_mouseAdapter
    extends java.awt.event.MouseAdapter {
  userUpdate adaptee;

  userUpdate_jButtonOK_mouseAdapter(userUpdate adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.jButtonOK_mouseClicked(e);
  }
}

⌨️ 快捷键说明

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