?? userupdate.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 + -