UpdatePass.java
上传用户:xinkaifrp
上传日期:2021-05-08
资源大小:372k
文件大小:8k
源码类别:

家庭/个人应用

开发平台:

Java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. /*
  6.  * UpdatePass.java
  7.  *
  8.  * Created on 2009-6-25, 16:51:37
  9.  */
  10. package com.financing;
  11. import com.financing.dao.LoginDao;
  12. import java.awt.Dimension;
  13. import javax.swing.JOptionPane;
  14. /**
  15.  *
  16.  * @author Administrator
  17.  */
  18. public class UpdatePass extends javax.swing.JFrame {
  19.     /** Creates new form UpdatePass */
  20.     public UpdatePass() {
  21.         initComponents();
  22.         Dimension d=this.getToolkit().getScreenSize();
  23.         Dimension d1=this.getSize();
  24.         this.setLocation((d.width-d1.width)/2, (d.height-d1.height)/2);
  25.     }
  26.     /** This method is called from within the constructor to
  27.      * initialize the form.
  28.      * WARNING: Do NOT modify this code. The content of this method is
  29.      * always regenerated by the Form Editor.
  30.      */
  31.     @SuppressWarnings("unchecked")
  32.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  33.     private void initComponents() {
  34.         toldpass = new javax.swing.JPasswordField();
  35.         tnewPass = new javax.swing.JPasswordField();
  36.         tconfirm = new javax.swing.JPasswordField();
  37.         bConfirm = new javax.swing.JButton();
  38.         bCancel = new javax.swing.JButton();
  39.         jLabel1 = new javax.swing.JLabel();
  40.         jLabel2 = new javax.swing.JLabel();
  41.         jLabel3 = new javax.swing.JLabel();
  42.         setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  43.         toldpass.addActionListener(new java.awt.event.ActionListener() {
  44.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  45.                 toldpassActionPerformed(evt);
  46.             }
  47.         });
  48.         bConfirm.setText("确认");
  49.         bConfirm.addActionListener(new java.awt.event.ActionListener() {
  50.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  51.                 bConfirmActionPerformed(evt);
  52.             }
  53.         });
  54.         bCancel.setText("取消");
  55.         bCancel.addActionListener(new java.awt.event.ActionListener() {
  56.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  57.                 bCancelActionPerformed(evt);
  58.             }
  59.         });
  60.         jLabel1.setText("原密码");
  61.         jLabel2.setText("新密码");
  62.         jLabel3.setText("新密码确认");
  63.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  64.         getContentPane().setLayout(layout);
  65.         layout.setHorizontalGroup(
  66.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  67.             .addGroup(layout.createSequentialGroup()
  68.                 .addContainerGap()
  69.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  70.                     .addGroup(layout.createSequentialGroup()
  71.                         .addComponent(bConfirm)
  72.                         .addGap(68, 68, 68)
  73.                         .addComponent(bCancel)
  74.                         .addContainerGap())
  75.                     .addGroup(layout.createSequentialGroup()
  76.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  77.                             .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  78.                                 .addComponent(jLabel3)
  79.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  80.                                 .addComponent(tconfirm, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
  81.                             .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
  82.                                 .addComponent(jLabel1)
  83.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
  84.                                 .addComponent(toldpass, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
  85.                             .addGroup(layout.createSequentialGroup()
  86.                                 .addComponent(jLabel2)
  87.                                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
  88.                                 .addComponent(tnewPass, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
  89.                         .addGap(146, 146, 146))))
  90.         );
  91.         layout.setVerticalGroup(
  92.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  93.             .addGroup(layout.createSequentialGroup()
  94.                 .addGap(42, 42, 42)
  95.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  96.                     .addComponent(toldpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  97.                     .addComponent(jLabel1))
  98.                 .addGap(37, 37, 37)
  99.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  100.                     .addComponent(tnewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  101.                     .addComponent(jLabel2))
  102.                 .addGap(35, 35, 35)
  103.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  104.                     .addComponent(jLabel3)
  105.                     .addComponent(tconfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  106.                 .addGap(47, 47, 47)
  107.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  108.                     .addComponent(bCancel)
  109.                     .addComponent(bConfirm))
  110.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  111.         );
  112.         pack();
  113.     }// </editor-fold>//GEN-END:initComponents
  114.     private void toldpassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toldpassActionPerformed
  115.         // TODO add your handling code here:
  116. }//GEN-LAST:event_toldpassActionPerformed
  117.     private void bCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelActionPerformed
  118.         dispose();
  119.     }//GEN-LAST:event_bCancelActionPerformed
  120.     private void bConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConfirmActionPerformed
  121.         String oldPass=new String(toldpass.getPassword());
  122.         String newPass=new String(tnewPass.getPassword());
  123.         String confirmPass=new String(tconfirm.getPassword());
  124.         LoginDao loginDao=new LoginDao();
  125.         if(oldPass.equals("")||newPass.equals("")||confirmPass.equals("")){
  126.              JOptionPane.showMessageDialog(rootPane, "输入不能为空");
  127.         }else  if(!newPass.equals(confirmPass)){
  128.              JOptionPane.showMessageDialog(rootPane, "两次密码输入不一致");
  129.         }else        
  130.         if(!loginDao.login(userName, oldPass)){
  131.             //原密码不正确
  132.             JOptionPane.showMessageDialog(rootPane, "输入原密码不正确");
  133.         }else{
  134.             //修改密码
  135.             LoginDao dao=new LoginDao();
  136.             if(!dao.updatePassword(userName, newPass)){
  137.                 JOptionPane.showMessageDialog(rootPane, "更新失败!");
  138.             }
  139.             dispose();
  140.         }
  141.         
  142.     }//GEN-LAST:event_bConfirmActionPerformed
  143.     /**
  144.     * @param args the command line arguments
  145.     */
  146.     public static void main(String args[]) {
  147.         java.awt.EventQueue.invokeLater(new Runnable() {
  148.             public void run() {
  149.                 new UpdatePass().setVisible(true);
  150.             }
  151.         });
  152.     }
  153.     private String userName;
  154.     public void setUserName(String userName) {
  155.         this.userName = userName;
  156.     }
  157.     // Variables declaration - do not modify//GEN-BEGIN:variables
  158.     private javax.swing.JButton bCancel;
  159.     private javax.swing.JButton bConfirm;
  160.     private javax.swing.JLabel jLabel1;
  161.     private javax.swing.JLabel jLabel2;
  162.     private javax.swing.JLabel jLabel3;
  163.     private javax.swing.JPasswordField tconfirm;
  164.     private javax.swing.JPasswordField tnewPass;
  165.     private javax.swing.JPasswordField toldpass;
  166.     // End of variables declaration//GEN-END:variables
  167. }