📄 changepasswordjpanel.java
字号:
/* * ChangePasswordJPanel.java * * Created on 2009年1月11日, 下午6:37 */package passengertransportmis;import org.jdesktop.application.Action;import java.sql.Connection;import java.sql.Statement;/** * * @author Degree41 */public class ChangePasswordJPanel extends javax.swing.JPanel { /** Creates new form ChangePasswordJPanel */ public ChangePasswordJPanel() { initComponents(); } @Action public void confirm() { if (this.oldPasswordField.getText().isEmpty() || this.newPasswordField.getText().isEmpty() || this.confirmPasswordField.getText().isEmpty()) { javax.swing.JOptionPane.showMessageDialog(this, "更新密码,以上三个文本框不得为空!", "请确认输入", 2/*warning*/); return; } Connection conn = Database.getConn(); Statement stmt = Database.createStmt(conn); String sql = new String("update user set password = '" + this.newPasswordField.getText() + "' where id = '" + PassengerTransportMISApp.getUserInfo()[0] /*userid*/+ "';"); int i = Database.executeUpdate(stmt, sql); if(i == 1) javax.swing.JOptionPane.showMessageDialog(this, "修改密码成功!", "提示", 1/*infomation*/); else javax.swing.JOptionPane.showMessageDialog(this, "修改密码失败,请确保你原本的用户信息正确!", "错误", 0/*erroe*/); } @Action public void cancel() { this.oldPasswordField.setText(""); this.newPasswordField.setText(""); this.confirmPasswordField.setText(""); } /** 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. */ @SuppressWarnings("unchecked") // <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(); cancelButton = new javax.swing.JButton(); confirmButton = new javax.swing.JButton(); oldPasswordField = new javax.swing.JPasswordField(); newPasswordField = new javax.swing.JPasswordField(); confirmPasswordField = new javax.swing.JPasswordField(); setName("Form"); // NOI18N org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getResourceMap(ChangePasswordJPanel.class); jLabel1.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N jLabel1.setName("jLabel1"); // NOI18N jLabel2.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N jLabel2.setName("jLabel2"); // NOI18N jLabel3.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N jLabel3.setName("jLabel3"); // NOI18N javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(passengertransportmis.PassengerTransportMISApp.class).getContext().getActionMap(ChangePasswordJPanel.class, this); cancelButton.setAction(actionMap.get("cancel")); // NOI18N cancelButton.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N cancelButton.setText(resourceMap.getString("cancelButton.text")); // NOI18N cancelButton.setName("cancelButton"); // NOI18N confirmButton.setAction(actionMap.get("confirm")); // NOI18N confirmButton.setFont(resourceMap.getFont("cancelButton.font")); // NOI18N confirmButton.setText(resourceMap.getString("confirmButton.text")); // NOI18N confirmButton.setName("confirmButton"); // NOI18N oldPasswordField.setFont(resourceMap.getFont("oldPasswordField.font")); // NOI18N oldPasswordField.setText(resourceMap.getString("oldPasswordField.text")); // NOI18N oldPasswordField.setName("oldPasswordField"); // NOI18N oldPasswordField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { oldPasswordFieldFocusLost(evt); } }); newPasswordField.setFont(resourceMap.getFont("oldPasswordField.font")); // NOI18N newPasswordField.setText(resourceMap.getString("newPasswordField.text")); // NOI18N newPasswordField.setName("newPasswordField"); // NOI18N confirmPasswordField.setFont(resourceMap.getFont("oldPasswordField.font")); // NOI18N confirmPasswordField.setText(resourceMap.getString("confirmPasswordField.text")); // NOI18N confirmPasswordField.setName("confirmPasswordField"); // NOI18N confirmPasswordField.addFocusListener(new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { confirmPasswordFieldFocusLost(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(175, 175, 175) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2) .addComponent(jLabel3)) .addGap(48, 48, 48) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(oldPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(newPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(confirmPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addComponent(confirmButton) .addGap(28, 28, 28) .addComponent(cancelButton) .addGap(25, 25, 25))) .addContainerGap(200, Short.MAX_VALUE)) ); layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jLabel1, jLabel2, jLabel3}); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(93, Short.MAX_VALUE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(oldPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(43, 43, 43) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel2) .addComponent(newPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(49, 49, 49) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel3) .addComponent(confirmPasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(70, 70, 70) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(confirmButton) .addComponent(cancelButton)) .addGap(82, 82, 82)) ); layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {cancelButton, confirmButton, confirmPasswordField, jLabel1, jLabel2, jLabel3, newPasswordField, oldPasswordField}); }// </editor-fold>//GEN-END:initComponents private void oldPasswordFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_oldPasswordFieldFocusLost // TODO add your handling code here: if(!this.oldPasswordField.getText().equals(PassengerTransportMISApp.getUserInfo()[2])){ javax.swing.JOptionPane.showMessageDialog(this, "密码错误,请重新输入!", "请重新输入", 0/*error*/); this.oldPasswordField.setText(""); } }//GEN-LAST:event_oldPasswordFieldFocusLost private void confirmPasswordFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_confirmPasswordFieldFocusLost // TODO add your handling code here: if(!this.confirmPasswordField.getText().equals(this.newPasswordField.getText())){ javax.swing.JOptionPane.showMessageDialog(this, "密码确认错误,请重新确认!", "请重新输入", 0/*error*/); this.confirmPasswordField.setText(""); } }//GEN-LAST:event_confirmPasswordFieldFocusLost // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JButton confirmButton; private javax.swing.JPasswordField confirmPasswordField; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JPasswordField newPasswordField; private javax.swing.JPasswordField oldPasswordField; // End of variables declaration//GEN-END:variables}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -