⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 passwordedit_frame.java~16~

📁 用java实现的学生管理系统
💻 JAVA~16~
字号:
package xscjgl;

import java.awt.*;
import java.sql.*;
import java.util.*;
import javax.swing.*;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.sql.ResultSet;
import javax.swing.BorderFactory;
import javax.swing.border.TitledBorder;
import xscjgl.Jdbcconn;
import java.awt.Font;
import java.awt.Rectangle;

/**
 * <p>Title: java xscjgl</p>
 *
 * <p>Description:学生查成绩,管理员输成绩、管理。二种权限的学生成绩管理系统 </p>
 *
 * <p>Copyright: lixing (c) 2006</p>
 *
 *
 * @author 04级计算机教育班 黎兴
 * @version 1.0
 */
public class PasswordEdit_Frame extends JFrame {
    JPanel jPanel1 = new JPanel();
    JButton jButton1 = new JButton();
    JButton jButton2 = new JButton();
    JLabel jLabel1 = new JLabel();
    XYLayout xYLayout2 = new XYLayout();
    JLabel jLabel2 = new JLabel();
    JLabel jLabel3 = new JLabel();
    JPasswordField jPasswordField1 = new JPasswordField();
    JPasswordField jPasswordField2 = new JPasswordField();
    JPasswordField jPasswordField3 = new JPasswordField();
    String BeforeUno;
    TitledBorder titledBorder1 = new TitledBorder("");
    JLabel jLabel4 = new JLabel();

    public PasswordEdit_Frame() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        getContentPane().setLayout(null);
        this.setTitle("修改密码窗体");
        this.getContentPane().setBackground(new Color(66, 168, 227));
        this.setForeground(Color.lightGray);
        jPanel1.setBackground(new Color(241, 249, 249));
        jPanel1.setBorder(BorderFactory.createEtchedBorder());
        jPanel1.setBounds(new Rectangle(39, 47, 329, 140));
        jPanel1.setLayout(xYLayout2);
        jButton1.setBounds(new Rectangle(91, 219, 76, 26));
        jButton1.setText("提交");
        jButton1.addActionListener(new
                                   PasswordEdit_Frame_jButton1_actionAdapter(this));
        jButton2.setBounds(new Rectangle(219, 219, 74, 26));
        jButton2.setText("退出");
        jButton2.addActionListener(new
                                   PasswordEdit_Frame_jButton2_actionAdapter(this));
        jLabel1.setText("请输入原密码:");
        jLabel2.setText("请输入新密码:");
        jLabel3.setText("再次输入新密码:");
        jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 16));
        jLabel4.setText("修改密码");
        jLabel4.setBounds(new Rectangle(143, 5, 85, 24));
        jPanel1.add(jLabel1, new XYConstraints(44, 14, 97, 24));
        jPanel1.add(jPasswordField1, new XYConstraints(167, 14, 114, -1));
        jPanel1.add(jLabel2, new XYConstraints(44, 53, 96, -1));
        jPanel1.add(jLabel3, new XYConstraints(43, 86, 111, -1));
        jPanel1.add(jPasswordField2, new XYConstraints(167, 46, 112, -1));
        jPanel1.add(jPasswordField3, new XYConstraints(167, 81, 110, -1));
        this.getContentPane().add(jButton1, null);
        this.getContentPane().add(jButton2, null);
        this.getContentPane().add(jLabel4, null);
        this.getContentPane().add(jPanel1, null);

    }

    public void jButton2_actionPerformed(ActionEvent e) {
        dispose();
    }

    public void jButton1_actionPerformed(ActionEvent e) {
        String BeforePassword = jPasswordField1.getText().trim().toString();
        String NewPassword = jPasswordField2.getText().trim().toString();
        String AgainPassword = jPasswordField3.getText().trim().toString();

        if (BeforePassword.equals("") || NewPassword.equals("") ||
            AgainPassword.equals(""))
        {
            JOptionPane.showMessageDialog(null, "密码不能为空,请按要求输入!");
        } else {
//******************************************************************************
             //判断原密码是否正确
            try{
                Jdbcconn conn = new Jdbcconn();
                conn.OpenConn("tqti","tqti","111111");
                String strSQL = "select * from UserTable where Uno='" +
                                BeforeUno + "'";
                ResultSet rs = conn.getResults(strSQL);
                rs.first();
                String Upassword=rs.getString("Upwd");
                if(Upassword.equals(BeforePassword))
                {
                    //验证新密码。
                    if(NewPassword.equals(AgainPassword))
                    {
                    //密码验证成功。更新密码。
                    try{
                        conn.executeUpdate("update UserTable set Upwd='"+NewPassword+"' where Uno='"+BeforeUno+"'");
                        System.out.println("update SQL is : update UserTable set Upwd='"+NewPassword+"' where Uno='"+BeforeUno+"'");
                        JOptionPane.showMessageDialog(null, "密码修改成功,请牢记您的新密码");
                        dispose();
                        conn.closeStmt();
                        conn.closeConn();
                    }catch(Exception ex)
                    {
                      JOptionPane.showMessageDialog(null, "密码修改失败,请重试!");
                      System.out.println(ex.getMessage());
                    }

                    }else{
                     JOptionPane.showMessageDialog(null, "两次新密码不一致,请重新输入!");
                     jPasswordField2.setText("");
                     jPasswordField3.setText("");
                    }

                }else{
                JOptionPane.showMessageDialog(null, "原密码错误,请输入正确的原始密码!");
                jPasswordField1.setText("");
                }
            }catch(Exception ex)
            {
                JOptionPane.showMessageDialog(null, "first exception has catched!");
                System.out.println(ex.getMessage());
            }

        }

    }

    public static void main(String args[]){
        PasswordEdit_Frame passwordFrame = new PasswordEdit_Frame();
        passwordFrame.setVisible(true);
        passwordFrame.setLocationRelativeTo(null);
        passwordFrame.setSize(new Dimension(400,400));

    }



}


class PasswordEdit_Frame_jButton1_actionAdapter implements ActionListener {
    private PasswordEdit_Frame adaptee;
    PasswordEdit_Frame_jButton1_actionAdapter(PasswordEdit_Frame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}


class PasswordEdit_Frame_jButton2_actionAdapter implements ActionListener {
    private PasswordEdit_Frame adaptee;
    PasswordEdit_Frame_jButton2_actionAdapter(PasswordEdit_Frame adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton2_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -