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

📄 usermodify.java

📁 学生成绩管理系统,可以修改
💻 JAVA
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserModify extends JFrame implements ActionListener {   
	DataBaseManager db=new DataBaseManager();
    ResultSet rs;
   JLabel jLabel1;
	JLabel jLabel2;
    JLabel jLabel4;
    private JLabel jLabel5;
    JButton jButton2;
	JButton jButton1;
	JPasswordField jPasswordField3;
	JPasswordField jPasswordField2;
	JLabel jLabel3;
	JPasswordField jPasswordField1;
	JTextField jTextField1;
                 public UserModify(){
            	 this.setLayout(null);
               	 this.setBounds(431, 223, 272, 295);
            	 this.setTitle("修改密码");
            	 this.setResizable(false);
            	 this.setVisible(true);
            	 {
            		 jLabel1 = new JLabel();
            		 getContentPane().add(jLabel1);
            		 jLabel1.setText("用户名:");
            		 jLabel1.setBounds(61, 33, 54, 15);
            	 }
            	 {
            		 jTextField1 = new JTextField();
            		 getContentPane().add(jTextField1);
            		 jTextField1.setText("");
            		 jTextField1.setBounds(127, 29, 105, 22);
            	 }
            	 {
            		 jLabel2 = new JLabel();
            		 getContentPane().add(jLabel2);
            		 jLabel2.setText("原密码:");
            		 jLabel2.setBounds(60, 74, 55, 15);
            	 }
            	 {
            		 jPasswordField1 = new JPasswordField();
            		 getContentPane().add(jPasswordField1);
            		 jPasswordField1.setEchoChar('*');
            		 jPasswordField1.setText("");
            		 jPasswordField1.setBounds(127, 70, 105, 22);
            	 }
            	 {
            		 jLabel3 = new JLabel();
            		 getContentPane().add(jLabel3);
            		 jLabel3.setText("新密码:");
            		 jLabel3.setBounds(60, 112, 55, 15);
            	 }
            	 {
            		 jPasswordField2 = new JPasswordField();
            		 getContentPane().add(jPasswordField2);
            		 jPasswordField2.setEchoChar('*');
            		 jPasswordField2.setText("");
            		 jPasswordField2.setBounds(127, 108, 105, 22);
            	 }
            	 {
            		 jLabel4 = new JLabel();
            		 getContentPane().add(jLabel4);
            		 jLabel4.setText("确认密码:");
            		 jLabel4.setBounds(54, 153, 67, 15);
            	 }
            	 {
            		 jPasswordField3 = new JPasswordField();
            		 getContentPane().add(jPasswordField3);
            		 jPasswordField3.setEchoChar('*');
            		 jPasswordField3.setText("");
            		 jPasswordField3.setBounds(127, 149, 105, 22);
            	 }
            	 {
            		 jButton1 = new JButton();
            		 jButton1.addActionListener(this);
            		 getContentPane().add(jButton1);
            		 jButton1.setText("修改");
            		 jButton1.setBounds(54, 211, 66, 22);
            	 }
            	 {
            		 jButton2 = new JButton();
            		 jButton2.addActionListener(this);
            		 getContentPane().add(jButton2);
            		 jButton2.setText("取消");
            		 jButton2.setBounds(159, 211, 67, 22);
            	 }
            	 {
            		 jLabel5 = new JLabel();
            		 getContentPane().add(jLabel5);
            		 jLabel5.setText("jLabel5");
            		 jLabel5.setIcon(new ImageIcon(getClass().getClassLoader().getResource("login.jpg")));
            		 jLabel5.setBounds(-38, -269, 1419, 700);
            	 }

             }
             public void actionPerformed(ActionEvent e)
         	{
         		if(e.getSource()== jButton2)
         		{
       			     this.dispose();
         		}
         		else if(e.getSource()==jButton1)
         		{
         			try
         			{
         				char[] password= jPasswordField1.getPassword();
         			        String passwordSTR=new String(password);
         			   char[] newPassword= jPasswordField2.getPassword();
         			        String newPasswordSTR=new String(newPassword);
         			    char[] confirmPassword= jPasswordField3.getPassword();
         			        String confirmPasswordSTR=new String(confirmPassword);
         				String strSQL="select * from [user1] where UserName='"+
         				jTextField1.getText().trim()+"'and PassWord='"+
         				 passwordSTR+"'";
         				if(jTextField1.getText().trim().equals(""))
         				{
         					JOptionPane.showMessageDialog(null,"用户名不能为空!");
         				}
         				else if(passwordSTR.equals(""))
         				{
         					JOptionPane.showMessageDialog(null,"原密码不能为空!");
         				}
         				else if(!newPasswordSTR.equals(confirmPasswordSTR))
         				{
         					JOptionPane.showMessageDialog(null,"两次输入的新密码不一致!");
         				}
         				else 
         				{
         					if(!db.getResult(strSQL).first())
         				        {
         					          JOptionPane.showMessageDialog(null,"此用户不存在或者原密码不正确!");
         					 
         				        }
         				        else
         				        {
         				        	strSQL="update [user1] set PassWord='"+
         				        	newPasswordSTR+"'where UserName='"+jTextField1.getText()
         				        	.trim()+"'";
         				        	if(db.updateSql(strSQL))
         				        	{
         				        		JOptionPane.showMessageDialog(null,"更新密码成功!");
         				        		this.dispose();
         				        	}
         				        	else
         				        	{
         				        		JOptionPane.showMessageDialog(null,"更新密码失败!");
         				        		this.dispose();
         				        	}
         				        	db.closeConnection();
         				        }
         				}
         			}
         			catch(SQLException sqle)
         			{
         				System.out.println(sqle.toString());
         			}
         			catch(Exception ex)
         			{
         				System.out.println(ex.toString());
         			}
         		}
        }
}

⌨️ 快捷键说明

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