📄 asspassword.java
字号:
/*
* Asspassword.java
*
* Created on 2007年11月17日, 下午7:00
*/
package javaapplication1;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;
/**
*
* @author mis05
*/
public class Asspassword extends javax.swing.JPanel {
/** Creates new form Asspassword */
public Asspassword() {
initComponents();
}
/** 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=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jPasswordField1 = new javax.swing.JPasswordField();
jPasswordField2 = new javax.swing.JPasswordField();
jPasswordField3 = new javax.swing.JPasswordField();
jButton1 = new javax.swing.JButton();
jLabel1.setText("\u539f\u5bc6\u7801");
jLabel2.setText("\u65b0\u5bc6\u7801");
jLabel3.setText("\u786e\u8ba4\u65b0\u5bc6\u7801");
jButton1.setText("\u786e\u5b9a");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
password(evt);
}
});
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(101, 101, 101)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2)
.add(jLabel3))
.add(29, 29, 29)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jPasswordField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
.add(jPasswordField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
.add(jPasswordField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
.add(113, 113, 113))
.add(layout.createSequentialGroup()
.add(153, 153, 153)
.add(jButton1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 77, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(170, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap(54, Short.MAX_VALUE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel1)
.add(jPasswordField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(31, 31, 31)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel2)
.add(jPasswordField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(23, 23, 23)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel3)
.add(jPasswordField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(40, 40, 40)
.add(jButton1)
.add(57, 57, 57))
);
}// </editor-fold>//GEN-END:initComponents
private void password(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_password
char password1[] = jPasswordField1.getPassword();
char password2[] = jPasswordField2.getPassword();
char password3[] = jPasswordField3.getPassword();
String pass1 = "";
String pass2 = "";
String pass3 = "";
for( int count = 0; count < password1.length; count++ )
pass1 += password1[ count ];
for( int count = 0; count < password2.length; count++ )
pass2 += password2[ count ];
for( int count = 0; count < password3.length; count++ )
pass3 += password3[ count ];
Statement sql;
try
{
Conect conect=new Conect();
sql=conect.dbConn.createStatement();
String passWord = "";
ResultSet resultset1 = sql.executeQuery("SELECT 密码 FROM 教务管理员 WHERE 登录 = 1");
while( resultset1.next() )
{
passWord = ( String ) resultset1.getObject(1);
}
if( pass1.equals(passWord) == false )
{
JOptionPane.showMessageDialog(null,"原密码错误","错误",JOptionPane.ERROR_MESSAGE);
}
else
if( pass2.equals(pass3) )
{
String update = "UPDATE 教务管理员 SET 密码='" + pass2 + "' WHERE 登录 = 1";
int reg;
reg = sql.executeUpdate( update );
JOptionPane.showMessageDialog(null,"已成功修改密码","成功",JOptionPane.INFORMATION_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"两次输入新密码不相同错误","错误",JOptionPane.ERROR_MESSAGE);
}
}
catch(SQLException sqlException){
JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
System.exit(1);}
catch(ClassNotFoundException classNotFound){
JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
System.exit(1);}// TODO add your handling code here:
}//GEN-LAST:event_password
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPasswordField jPasswordField1;
private javax.swing.JPasswordField jPasswordField2;
private javax.swing.JPasswordField jPasswordField3;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -