📄 modifypanel.java
字号:
package file2;
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ModifyPanel extends JPanel implements ActionListener{
private DBConnection con=null;
private JLabel tip=null;
private JLabel oldPassword=null;
private JLabel newPassword=null;
private JLabel reNewPassword=null;
private JTextField oldPasswordTextField=null;
private JTextField newPasswordTextField=null;
private JTextField reNewPasswordTextField=null;
private JButton confirm=null;
private JButton reset=null;
private JPanel tipPane=null;
private JPanel passwordPane=null;
private JPanel buttonsPane=null;
private JPanel echoPane=null;//用来装载passwordPane和buttonsPane
public ModifyPanel(){
tip=new JLabel("提示:只能修改您自己的密码,如果您要修改用户名,请您转到添加管理员界面添加新管理员即可.");
oldPassword=new JLabel("原密码:");
newPassword=new JLabel("新密码:");
reNewPassword=new JLabel("再次输入新密码:");
oldPasswordTextField=new JTextField(20);
newPasswordTextField=new JTextField(20);
reNewPasswordTextField=new JTextField(20);
confirm=new JButton("确定");
reset=new JButton("重置");
//装载tip标签
tipPane=new JPanel();
tipPane.setLayout(new FlowLayout(FlowLayout.CENTER));
tipPane.add(tip);
passwordPane=new JPanel();
passwordPane.setLayout(new GridLayout(3,2));
passwordPane.add(oldPassword);
passwordPane.add(oldPasswordTextField);
passwordPane.add(newPassword);
passwordPane.add(newPasswordTextField);
passwordPane.add(reNewPassword);
passwordPane.add(reNewPasswordTextField);
//装载buttons 按钮
buttonsPane=new JPanel();
buttonsPane.setLayout(new FlowLayout(FlowLayout.CENTER));
buttonsPane.add(confirm);
buttonsPane.add(reset);
//装载tipPane和buttonsPane
echoPane=new JPanel();
echoPane.setLayout(new GridLayout(2,1));
echoPane.add(passwordPane);
echoPane.add(buttonsPane);
this.setLayout(new GridLayout(2,1));
this.add(tipPane);
this.add(echoPane);
confirm.addActionListener(this);
reset.addActionListener(this);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==reset){
oldPasswordTextField.setText("");
newPasswordTextField.setText("");
reNewPasswordTextField.setText("");
return;
}
if(e.getSource()==confirm){
String oldPassword=oldPasswordTextField.getText().trim();
String newPassword=newPasswordTextField.getText().trim();
String reNewPassword=reNewPasswordTextField.getText().trim();
if(oldPassword.equals("")||newPassword.equals("")||reNewPassword.equals("")){
JOptionPane.showMessageDialog(null, "所有密码都不能为空,请重新输入!", "警告", JOptionPane.ERROR_MESSAGE);
return;
}
if(!(newPassword.equals(reNewPassword))){
JOptionPane.showMessageDialog(null, "两次输入的新密码不一致,请重新输入!", "警告", JOptionPane.ERROR_MESSAGE);
return;
}else if(oldPassword.equals(newPassword)){
JOptionPane.showMessageDialog(null, "您没有修改密码!", "提示", JOptionPane.INFORMATION_MESSAGE);
return;
}else{
con=new DBConnection();
String querySql="select* from administrator where password='"+oldPassword+"'";
ResultSet set=con.executeSelect(querySql);
try{
if(!set.next()){
JOptionPane.showMessageDialog(null, "原密码输入有误,请重新输入!", "警告", JOptionPane.ERROR_MESSAGE);
return;
}
}catch(SQLException sql){
JOptionPane.showMessageDialog(null, "发生SQL错误!", "警告", JOptionPane.ERROR_MESSAGE);
return;
}
String updateSql="update administrator set password='"+newPassword+"' where password='"+oldPassword+"'";
con.executeDML(updateSql);
JOptionPane.showMessageDialog(null, "修改成功!", "提示", JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -