?? userupdate.java
字號:
package Manager;import javax.swing.*;import com.borland.jbcl.layout.*;import java.awt.*;import java.awt.event.*;import java.sql.*;/** * <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; //定義結(jié)果集 private DBManager db =new DBManager();//定義數(shù)據(jù)庫操作對象 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, 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對象執(zhí)行查詢過程 rs=db.getResult(strSQL) ; //判斷結(jié)果集是否為空 boolean isexist=false; try { isexist = rs.first(); } catch (SQLException ex1) { JOptionPane.showMessageDialog(null,ex1.toString() ); } //若為空,則說明用戶名不存在或密碼不正確,彈出警告信息,并設定主窗體權限為無 if(!isexist) {JOptionPane.showMessageDialog(null,"用戶名不存在,或原密碼不正確!"); return; } //若不為空,則說明用戶名存在且密碼正確,執(zhí)行更新過程 else { 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 + -