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

📄 user.java

📁 简单的书店管理系统,是课设期间教师指导完成的,希望会对大家有帮助!
💻 JAVA
字号:
package book;
//********************************************************************
//密码管理窗体
//********************************************************************
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;


public class User extends Mb{
	 private JLabel title,accounts,password,password1,password2;
	 private JTextField text;
	 private JPasswordField m1,m2,m3;
	 private ButtonIcon ok,close;
	 public User(String s, int i, int j ) {
		super(s,i,j);
		con.setLayout(null);
		shezhi();
		add();
	}
	 
	public void shezhi(){
		
		title=new JLabel("密码修改");
		title.setBounds(125,12,100,20);
		accounts=new JLabel("用户名");
		accounts.setBounds(45,50,80,18);;
		password=new JLabel("原始密码");
		password.setBounds(45,90,80,18);
		password1=new JLabel("新密码");
		password1.setBounds(45,130,80,18);
		password2=new JLabel("密码确认");
		password2.setBounds(45,170,80,18);
		
		text=new JTextField(18);
		text.setBounds(120,50,130,18);
		text.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
			   ok.doClick();	
			}
		});
		m1=new JPasswordField();
		m1.setBounds(120,90,130,18);
		m1.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				   ok.doClick();	
				}
			});
		m2=new JPasswordField();
		m2.setBounds(120,130,130,18);
		m2.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				   ok.doClick();	
				}
			});
		m3=new JPasswordField();
		m3.setBounds(120,170,130,18);
		m3.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0){
				   ok.doClick();	
				}
			});
		
		
		ok=new ButtonIcon("确定");
		ok.setBounds(45,220,75,27);
		ok.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				boolean boo=vdate();
				boolean bool=false;
				if(boo){
					try {
						bool=vldate();
					} catch (SQLException e) {
						e.printStackTrace();
					}
					if(bool){
						String  str;
						str="update dl set 密码='"+m2.getText()+"' where 用户名='"+text.getText()+"'";
						try {

							MainDAO dao=new MainDAO();
							 dao.update(str);
					         clueon();
						     } 
						catch (SQLException e) {e.printStackTrace();}
					}
					
				}
		   	
			}
			
		});
		close=new ButtonIcon("关闭");
		close.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				close();
			}
		});
		close.setBounds(180,220,70,25);
	}
	
	
	void add(){
		con.add(title);con.add(accounts);con.add(password);con.add(password1);con.add(password2);con.add(text);con.add(m1);con.add(m2);
		con.add(m3);con.add(ok);con.add(close);
	}
	
	
	boolean vdate(){
        boolean boo = false;
        if(text.getText().length()==0||m1.getText().length()==0||m3.getText().length()==0||m3.getText().length()==0){
        	JOptionPane.showMessageDialog(this, "用户名或密码不能为空!");
        }
        else
        	if(!m2.getText().equals(m3.getText())){
        		JOptionPane.showMessageDialog(this, "两次密码确认失败!");
        	}
        	else{
        		boo=true;	
        	}
		return boo;
	}
	
	boolean vldate() throws SQLException{
		String name,password;
		MainDAO dao=new MainDAO();
		ResultSet rs = dao.getSelect("SELECT * FROM dl ");
		boolean bool=false;
		boolean boo = false;
			while ((boo = rs.next()) == true) {
				name = rs.getString("用户名");
				password = rs.getString("密码");
				if (name.equals(text.getText()) && password.equals(m1.getText())) {
					bool=true;
					break;
				} else {
					JOptionPane.showMessageDialog(this, "没有此帐号,或原始密码有误!!!");
					break;
				}
			}
			return bool;
	}
	
	void clueon(){
		JOptionPane.showMessageDialog(this, "恭喜,密码修改成功!!!");
		close();
	}
}

⌨️ 快捷键说明

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