📄 userupdate.java~12~
字号:
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; //定义结果集 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.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(jLabel4, new XYConstraints(107, 202, 100, 30)); 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)); } 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; } 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) { 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,"成功更新!"); } 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 + -