📄 changepassword.java
字号:
/*
*修改密码界面
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class ChangePassword extends JFrame {
private String user_name;//接收要修改密码用户的登录名
/** 类的构造方法*/
public ChangePassword(String user_name) {
this.user_name = user_name;//获得用户的登录名
initComponents();
setVisible(true);
setResizable(false);//固定窗体
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
private void initComponents() {
jDialog1 = new javax.swing.JDialog();
jLabel4 = new javax.swing.JLabel();
jButton3 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jPasswordField2 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel3 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jPasswordField3 = new javax.swing.JPasswordField();
jDialog1.setBackground(java.awt.Color.white);
jDialog1.setBounds(new java.awt.Rectangle(350, 350, 500, 150));
jDialog1.setModal(true);
jLabel4.setFont(new java.awt.Font("宋体", 1, 16));
jLabel4.setText("\u5bc6\u7801\u4fee\u6539\u6210\u529f\uff01");
jButton3.setText("\u786e\u5b9a");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
jDialog1.getContentPane().setLayout(jDialog1Layout);
jDialog1Layout.setHorizontalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGroup(jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGap(172, 172, 172)
.addComponent(jLabel4))
.addGroup(jDialog1Layout.createSequentialGroup()
.addGap(193, 193, 193)
.addComponent(jButton3)))
.addContainerGap(172, Short.MAX_VALUE))
);
jDialog1Layout.setVerticalGroup(
jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jDialog1Layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(jLabel4)
.addGap(19, 19, 19)
.addComponent(jButton3)
.addContainerGap(40, Short.MAX_VALUE))
);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBounds(new java.awt.Rectangle(400, 300, 200, 200));
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jLabel1.setFont(new java.awt.Font("宋体", 1, 14));
jLabel1.setText("\u539f\u5bc6\u7801");
jLabel2.setFont(new java.awt.Font("宋体", 1, 14));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel2.setText("\u786e\u8ba4\u5bc6\u7801");
jPasswordField1.setEchoChar('*');
jPasswordField1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jPasswordField1KeyTyped(evt);
}
});
jPasswordField2.setEchoChar('*');
jPasswordField2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyTyped(java.awt.event.KeyEvent evt) {
jPasswordField2KeyTyped(evt);
}
});
jButton1.setText("\u786e\u8ba4");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("\u53d6\u6d88");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("宋体", 1, 12));
jLabel3.setForeground(new java.awt.Color(204, 0, 0));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel5.setFont(new java.awt.Font("宋体", 1, 14));
jLabel5.setText("\u65b0\u5bc6\u7801");
jPasswordField3.setEchoChar('*');
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(115, 115, 115)
.addComponent(jButton1)
.addGap(40, 40, 40)
.addComponent(jButton2)
.addContainerGap(96, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(32, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel5)
.addComponent(jLabel1)))
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jPasswordField3, 0, 0, Short.MAX_VALUE)
.addComponent(jPasswordField2)
.addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE))
.addGap(50, 50, 50))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addGap(36, 36, 36)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jPasswordField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(35, 35, 35)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jPasswordField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(32, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
this.setVisible(false);//
}//GEN-LAST:event_formWindowClosing
private void jPasswordField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField2KeyTyped
jLabel3.setText("");//重新输入确认时,取消错误提示信息
}//GEN-LAST:event_jPasswordField2KeyTyped
private void jPasswordField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jPasswordField1KeyTyped
jLabel3.setText("");//重新输入新密码时,取消错误信息
}//GEN-LAST:event_jPasswordField1KeyTyped
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
this.setVisible(false);//用户点击“取消”按钮时,关闭该修改密码界面
}//GEN-LAST:event_jButton2ActionPerformed
/**
* 用户在对话框点击“确认”后,关闭对话框和修改密码界面
*/
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
this.setVisible(false);
jDialog1.setVisible(false);
}//GEN-LAST:event_jButton3ActionPerformed
/**
*当用户点击“确认”后,先对用户输入的信息判断,若两次输入不一致,则会显示错误提示信息;
*输入正确后,连接数据库并进行数据库中数据的更新操作。
*/
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
//得到输入的原始密码
String oldPwd = String.valueOf(jPasswordField1.getPassword());
//得到输入的新密码
String newPwd1 = String.valueOf(jPasswordField2.getPassword());
//得到确认的新密码
String newPwd2 = String.valueOf(jPasswordField3.getPassword());
JDBC jdbc = new JDBC();//连接数据库
if(jdbc.oldPwdCheck(oldPwd, user_name)) {
if(newPwd1.equals(newPwd2)) {//检查两次输入的密码是否一致
//如果两次输入的密码一致,
//则弹出密码修改成功对话框
jDialog1.setVisible(true);
//调用方法,更新数据库中的信息
jdbc.changePassword(newPwd1,user_name);
} else {
jLabel3.setText("两次输入的密码不一致,请重新输入!");
}
} else {
jLabel3.setText("您输入的原密码不正确!");
}
}//GEN-LAST:event_jButton1ActionPerformed
// 变量声明 - 不进行修改//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JDialog jDialog1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private javax.swing.JPasswordField jPasswordField3;
// 变量声明结束//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -