?? changepassword.java
字號:
package StudentManageSystem.mainframeswing;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import StudentManageSystem.link.SQLRunner;
import java.sql.ResultSet;
import java.awt.*;
import java.sql.*;
class ChangePassword extends JDialog {
String id;
public ChangePassword(String id) {
try {
this.id=id;
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(null);
this.setSize(400,330);
this.setTitle("密碼修改");
jLabel1.setText("舊密碼");
jLabel1.setBounds(new Rectangle(46, 34, 83, 33));
jPasswordField_new2.setText("");
jPasswordField_new2.setBounds(new Rectangle(154, 167, 174, 40));
jLabel3.setText("確認新密碼");
jLabel3.setBounds(new Rectangle(46, 173, 130, 25));
jPasswordField_new1.setText("");
jPasswordField_new1.setBounds(new Rectangle(153, 101, 174, 38));
jLabel2.setText("新密碼");
jLabel2.setBounds(new Rectangle(46, 106, 78, 31));
jButton2.addActionListener(new ChangePassword_jButton2_actionAdapter(this));
jButton1.addActionListener(new ChangePassword_jButton1_actionAdapter(this));
jButton2.setBounds(new Rectangle(220, 241, 87, 31));
jButton2.setText("取消");
jButton1.setBounds(new Rectangle(96, 241, 85, 31));
jButton1.setText("確定");
this.getContentPane().add(jLabel1);
this.getContentPane().add(jLabel2);
this.getContentPane().add(jLabel3);
this.getContentPane().add(jButton1);
this.getContentPane().add(jButton2);
this.getContentPane().add(jPasswordField_new2);
this.getContentPane().add(jPasswordField_new1);
this.getContentPane().add(jPasswordField_old);
jPasswordField_old.setText("");
jPasswordField_old.setBounds(new Rectangle(154, 25, 173, 38));
this.setResizable(false);
}
JLabel jLabel1 = new JLabel();
JPasswordField jPasswordField_old = new JPasswordField();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField_new1 = new JPasswordField();
JLabel jLabel3 = new JLabel();
JPasswordField jPasswordField_new2 = new JPasswordField();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
public void jButton2_actionPerformed(ActionEvent e) {
this.dispose();
}
public void jButton1_actionPerformed(ActionEvent e) {
String old=new String(jPasswordField_old.getPassword());
ResultSet rs=SQLRunner.getResult("select * from mysysuser where id='"+id+"' and password='"+old+"'");
try {
if (rs.next()) {
String new1 = new String(jPasswordField_new1.getPassword());
String new2 = new String(jPasswordField_new2.getPassword());
if (new1.equals(new2)) {
if (SQLRunner.executSql("update mysysuser set password='" +
new1 + "' where id='" + id + "'")) {
JOptionPane.showMessageDialog(null, "密碼修改成功", "密碼修改",
JOptionPane.INFORMATION_MESSAGE);
this.dispose();
} else {
JOptionPane.showMessageDialog(null, "新密碼不應過長", "密碼修改",
JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(null, "新密碼不一致", "密碼修改",
JOptionPane.ERROR_MESSAGE);
return;
}
} else {
JOptionPane.showMessageDialog(null, "舊密碼錯誤", "密碼修改",
JOptionPane.ERROR_MESSAGE);
return;
}
} catch (HeadlessException ex) {
} catch (SQLException ex) {
}
}
}
class ChangePassword_jButton1_actionAdapter implements ActionListener {
private ChangePassword adaptee;
ChangePassword_jButton1_actionAdapter(ChangePassword adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
class ChangePassword_jButton2_actionAdapter implements ActionListener {
private ChangePassword adaptee;
ChangePassword_jButton2_actionAdapter(ChangePassword adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -