UpdatePass.java
上传用户:xinkaifrp
上传日期:2021-05-08
资源大小:372k
文件大小:8k
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * UpdatePass.java
- *
- * Created on 2009-6-25, 16:51:37
- */
- package com.financing;
- import com.financing.dao.LoginDao;
- import java.awt.Dimension;
- import javax.swing.JOptionPane;
- /**
- *
- * @author Administrator
- */
- public class UpdatePass extends javax.swing.JFrame {
- /** Creates new form UpdatePass */
- public UpdatePass() {
- initComponents();
- Dimension d=this.getToolkit().getScreenSize();
- Dimension d1=this.getSize();
- this.setLocation((d.width-d1.width)/2, (d.height-d1.height)/2);
- }
- /** 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() {
- toldpass = new javax.swing.JPasswordField();
- tnewPass = new javax.swing.JPasswordField();
- tconfirm = new javax.swing.JPasswordField();
- bConfirm = new javax.swing.JButton();
- bCancel = new javax.swing.JButton();
- jLabel1 = new javax.swing.JLabel();
- jLabel2 = new javax.swing.JLabel();
- jLabel3 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
- toldpass.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- toldpassActionPerformed(evt);
- }
- });
- bConfirm.setText("确认");
- bConfirm.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bConfirmActionPerformed(evt);
- }
- });
- bCancel.setText("取消");
- bCancel.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- bCancelActionPerformed(evt);
- }
- });
- jLabel1.setText("原密码");
- jLabel2.setText("新密码");
- jLabel3.setText("新密码确认");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(bConfirm)
- .addGap(68, 68, 68)
- .addComponent(bCancel)
- .addContainerGap())
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addComponent(jLabel3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(tconfirm, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
- .addComponent(jLabel1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
- .addComponent(toldpass, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
- .addComponent(tnewPass, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)))
- .addGap(146, 146, 146))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(42, 42, 42)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(toldpass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel1))
- .addGap(37, 37, 37)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(tnewPass, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jLabel2))
- .addGap(35, 35, 35)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
- .addComponent(jLabel3)
- .addComponent(tconfirm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addGap(47, 47, 47)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(bCancel)
- .addComponent(bConfirm))
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void toldpassActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toldpassActionPerformed
- // TODO add your handling code here:
- }//GEN-LAST:event_toldpassActionPerformed
- private void bCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bCancelActionPerformed
- dispose();
- }//GEN-LAST:event_bCancelActionPerformed
- private void bConfirmActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bConfirmActionPerformed
- String oldPass=new String(toldpass.getPassword());
- String newPass=new String(tnewPass.getPassword());
- String confirmPass=new String(tconfirm.getPassword());
- LoginDao loginDao=new LoginDao();
- if(oldPass.equals("")||newPass.equals("")||confirmPass.equals("")){
- JOptionPane.showMessageDialog(rootPane, "输入不能为空");
- }else if(!newPass.equals(confirmPass)){
- JOptionPane.showMessageDialog(rootPane, "两次密码输入不一致");
- }else
- if(!loginDao.login(userName, oldPass)){
- //原密码不正确
- JOptionPane.showMessageDialog(rootPane, "输入原密码不正确");
- }else{
- //修改密码
- LoginDao dao=new LoginDao();
- if(!dao.updatePassword(userName, newPass)){
- JOptionPane.showMessageDialog(rootPane, "更新失败!");
- }
- dispose();
- }
-
- }//GEN-LAST:event_bConfirmActionPerformed
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new UpdatePass().setVisible(true);
- }
- });
- }
- private String userName;
- public void setUserName(String userName) {
- this.userName = userName;
- }
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton bCancel;
- private javax.swing.JButton bConfirm;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JPasswordField tconfirm;
- private javax.swing.JPasswordField tnewPass;
- private javax.swing.JPasswordField toldpass;
- // End of variables declaration//GEN-END:variables
- }