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

📄 passwordchange.java

📁 可以用的成绩管理系统
💻 JAVA
字号:
/**
 * @(#)PasswordChange.java
 *
 *
 * @author 
 * @version 1.00 2008/7/6
 */


import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;


public class PasswordChange extends JFrame implements ActionListener{
	//JDialog jDlg = new JDialog();
	
	JLabel jl1,jl2,jl3,jl4;
	JTextField jtf1,jtf2;
	JPasswordField jtf3,jtf4;
	JPanel jpl1,jpl2,jpl3,jpl4,jpl5;
	
	DataBaseManager db = new DataBaseManager();
	ResultSet rs;
	Statement stmt;
	
	String str ;
	public PasswordChange(){
		this.setTitle("修改密码");
		str = Login.sName;
		JButton jbtn =new  JButton("确定");
		jbtn.addActionListener(this);
		jl1 = new JLabel("帐	        号:");
		jl2 = new JLabel("原始密码:");
		jl3 = new JLabel("新密码    :");
		jl4 = new JLabel("确认密码:");

		jtf1 = new JTextField(10);
		jtf1.setText(str);
		jtf1.setEditable(false);
		jtf2 = new JTextField(10);
		jtf3 = new JPasswordField(10);
		jtf3.setEchoChar('*');
		jtf4 = new JPasswordField(10);
		jtf4.setEchoChar('*');
		jpl1 = new JPanel();
		jpl2 = new JPanel();
		jpl3 = new JPanel();
		jpl4 = new JPanel();
		jpl5 = new JPanel();

		jpl1.setLayout(new FlowLayout(FlowLayout.CENTER));
		jpl1.add(jl1);
		jpl1.add(jtf1);

		jpl2.setLayout(new FlowLayout(FlowLayout.CENTER));
		jpl2.add(jl2);
		jpl2.add(jtf2);

		jpl3.setLayout(new FlowLayout(FlowLayout.CENTER));
		jpl3.add(jl3);
		jpl3.add(jtf3);

		jpl4.setLayout(new FlowLayout(FlowLayout.CENTER));
		jpl4.add(jl4);
		jpl4.add(jtf4);

		jpl5.setLayout(new FlowLayout(FlowLayout.CENTER));
		jpl5.add(jbtn);
		this.setLayout(new GridLayout(5,1));
		this.add(jpl1);
		this.add(jpl2);
		this.add(jpl3);
		this.add(jpl4);
		this.add(jpl5);


		this.setSize(400,300);
		this.setLocation((550-this.getWidth()/2),
				(375-this.getHeight()/2));
		
		this.setVisible(true);
		
	}
	public void actionPerformed(ActionEvent e){
		try{
			String oldpwd = jtf2.getText().trim();
			String strSQL1 ="select *from  Admin_Info where User_name='"+str+"'";
				rs =db.getResult(strSQL1);
				
				while(rs.next()){
					if(jtf2.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null,"请输入原始密码!","提示",JOptionPane.INFORMATION_MESSAGE);
						break;
					}else if(jtf3.getText().trim().equals("")){
				
						JOptionPane.showMessageDialog(null,"请输入新密码!","提示",JOptionPane.INFORMATION_MESSAGE);
						break;
					}else if(jtf4.getText().trim().equals("")){
				
						JOptionPane.showMessageDialog(null,"请确认密码!","提示",JOptionPane.INFORMATION_MESSAGE);
						break;
					}else if(!jtf4.getText().trim().equals(jtf3.getText().trim())){
				
						JOptionPane.showMessageDialog(null,"两次输入密码不一样!","提示",JOptionPane.INFORMATION_MESSAGE);
						break;
					}else if(!oldpwd.equals(rs.getString(3))){
						JOptionPane.showMessageDialog(null,"原始密码不正确!","提示",JOptionPane.ERROR_MESSAGE);
						jtf2.setText("");
						jtf3.setText("");
						jtf4.setText("");
						
					}else{
						
						String strSQL2="update Admin_Info set Password='"
								+jtf3.getText()+"'";
							
							//db.stmt.execute(strSQL2);
						if(db.updateSql(strSQL2)){
							
							JOptionPane.showMessageDialog(null,"修改密码成功!","提示",JOptionPane.INFORMATION_MESSAGE);	
							this.dispose();
						}else{
							
							JOptionPane.showMessageDialog(null,"修改密码失败!","提示",JOptionPane.INFORMATION_MESSAGE);
							this.dispose();
						}
					
					}
					rs.beforeFirst();
				}
				
				//db.closeConnection();
		}catch(SQLException ex){
				System.out.println(ex);
		}catch(NullPointerException ex){
				System.out.println(ex);
		}
	}
}

⌨️ 快捷键说明

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