📄 passworddialog.java
字号:
/**
* 源文件:PasswordDialog.java
* 作用:修改密码
*/
package mypro;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class PasswordDialog extends JDialog implements ActionListener
{
private JLabel labOldPwd,labNewPwd,labValidatePwd;
private JPasswordField OldPwd,NewPwd,ValidatePwd;
private JButton btnQueding,btnQuxiao;
static
{
//设置窗体为豪华框架
JDialog.setDefaultLookAndFeelDecorated(true);
}
public PasswordDialog(MainFrame owner,boolean bo)
{
super(owner,bo);
labOldPwd=new JLabel("旧密码:");
labNewPwd=new JLabel("新密码:");
labValidatePwd=new JLabel("确认密码:");
OldPwd=new JPasswordField();
NewPwd=new JPasswordField();
ValidatePwd=new JPasswordField();
btnQueding=new JButton("确定");
btnQuxiao=new JButton("取消");
labOldPwd.setBounds(40,30,60,20);
labNewPwd.setBounds(40,60,60,20);
labValidatePwd.setBounds(40,90,60,20);
OldPwd.setBounds(110,30,130,20);
NewPwd.setBounds(110,60,130,20);
ValidatePwd.setBounds(110,90,130,20);
btnQueding.setBounds(60,130,60,20);
btnQueding.setActionCommand("sure");
btnQueding.setToolTipText("密码被修改");
btnQuxiao.setBounds(150,130,60,20);
btnQuxiao.setActionCommand("quash");
btnQuxiao.setToolTipText("取消密码修改并关闭该窗体");
btnQueding.addActionListener(this);
btnQuxiao.addActionListener(this);
Container me=this.getContentPane();
me.setLayout(null);
me.add(labOldPwd);
me.add(labNewPwd);
me.add(labValidatePwd);
me.add(OldPwd);
me.add(NewPwd);
me.add(ValidatePwd);
me.add(btnQueding);
me.add(btnQuxiao);
this.setTitle("修改密码");
this.setSize(300,200);
this.setResizable(false);
this.setLocationRelativeTo(this);//窗体居中显示
this.setVisible(true);
}
public void actionPerformed(ActionEvent pwae)
{
String strbtn=pwae.getActionCommand();
if(strbtn.equals("sure"))
{
String strOldPwd=OldPwd.getText();
String strNewPwd=NewPwd.getText();
String strValidatePwd=ValidatePwd.getText();
UpdateData upd=new UpdateData();
if(strOldPwd.length()!=6)
{
JOptionPane.showMessageDialog(null,"请输入六位数密码","提示",JOptionPane.INFORMATION_MESSAGE);
OldPwd.setText("");
OldPwd.requestFocus();
}
else if(strNewPwd.length()!=6)
{
JOptionPane.showMessageDialog(null,"请输入六位数新密码","提示",JOptionPane.INFORMATION_MESSAGE);
NewPwd.setText("");
NewPwd.requestFocus();
}
else if(!strValidatePwd.equals(strNewPwd))
{
JOptionPane.showMessageDialog(null,"新密码与确认密码不符","提示",JOptionPane.INFORMATION_MESSAGE);
NewPwd.setText("");
ValidatePwd.setText("");
NewPwd.requestFocus();
}
else
{
if(upd.passwordUpdate(LandFrame.strCode,strOldPwd,strNewPwd))
{
JOptionPane.showMessageDialog(null,"密码修改成功","提示",JOptionPane.INFORMATION_MESSAGE);
OldPwd.setText("");
NewPwd.setText("");
ValidatePwd.setText("");
}
else
{
JOptionPane.showMessageDialog(null,"密码修改失败","提示",JOptionPane.INFORMATION_MESSAGE);
OldPwd.setText("");
NewPwd.setText("");
ValidatePwd.setText("");
}
}
}
else if(strbtn.equals("quash"))
{
this.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -