📄 userupdate.java
字号:
package Manager;
import javax.swing.*;
import com.borland.jbcl.layout.*;
import java.awt.event.*;
import java.sql.*;
public class userUpdate extends JFrame {
/**
* <p>Title: 操作员修改</p>
* <p>Description:操作员更新密码 </p>
* <p>Copyright: Copyright (c) 2008</p>
* <p>Company: 南华大学计算机系</p>
* @author 王云飞
* @version 1.0
*/
private static final long serialVersionUID = 1L;
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) {
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, 268, 91, 31));
this.getContentPane().add(jButtonCancel, new XYConstraints(243, 269, 94, 30));
this.getContentPane().add(jLabel3, new XYConstraints(105, 154, 62, 30));
this.getContentPane().add(jLabel4, new XYConstraints(102, 202, 100, 30));
}
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;
}
//若不为空,则说明用户名存在且密码正确,执行更新过程
else
{
strSQL="update user set Password='"+jPasswordnew.getText().trim()+"' where Username='"+jTextFieldusername.getText().trim() +"'";
if(db.executeSql(strSQL))
{JOptionPane.showMessageDialog(null,"成功更新!");
jTextFieldusername.setText("");}
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 + -