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

📄 userupdate.java

📁 图书馆系统
💻 JAVA
字号:
import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.Point;

import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import java.sql.*;

public class userUpdate extends JFrame {

	private static final long serialVersionUID = 1L;

	private JPanel jContentPane = null;

	private JLabel jLabel = null;

	private JLabel jLabel1 = null;

	private JLabel jLabel2 = null;

	private JLabel jLabel3 = null;

	private JTextField jTextFieldusername = null;

	private JPasswordField jPasswordold = null;

	private JPasswordField jPasswordnew = null;

	private JPasswordField jPasswordnewconfirm = null;

	private JButton jButtonOK = null;

	private JButton jButtonCancel = null;
	ResultSet rs;
	private DBManager db=new DBManager();

	public userUpdate() throws HeadlessException {
		// TODO 自动生成构造函数存根
		super();
		initialize();
	}

	public userUpdate(GraphicsConfiguration arg0) {
		super(arg0);
		// TODO 自动生成构造函数存根
		initialize();
	}

	public userUpdate(String arg0) throws HeadlessException {
		super(arg0);
		// TODO 自动生成构造函数存根
		initialize();
	}

	public userUpdate(String arg0, GraphicsConfiguration arg1) {
		super(arg0, arg1);
		// TODO 自动生成构造函数存根
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(344, 250);
		this.setContentPane(getJContentPane());
		this.setTitle("更改密码");
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel3 = new JLabel();
			jLabel3.setText("确认新密码");
			jLabel3.setSize(new Dimension(77, 20));
			jLabel3.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel3.setLocation(new Point(45, 120));
			jLabel2 = new JLabel();
			jLabel2.setText("新密码");
			jLabel2.setSize(new Dimension(77, 20));
			jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel2.setLocation(new Point(45, 90));
			jLabel1 = new JLabel();
			jLabel1.setText("原密码");
			jLabel1.setSize(new Dimension(77, 20));
			jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel1.setLocation(new Point(45, 60));
			jLabel = new JLabel();
			jLabel.setText("用户名");
			jLabel.setSize(new Dimension(77, 20));
			jLabel.setHorizontalAlignment(SwingConstants.CENTER);
			jLabel.setLocation(new Point(45, 30));
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(jLabel, null);
			jContentPane.add(jLabel1, null);
			jContentPane.add(jLabel2, null);
			jContentPane.add(jLabel3, null);
			jContentPane.add(getJTextFieldusername(), null);
			jContentPane.add(getJPasswordold(), null);
			jContentPane.add(getJPasswordnew(), null);
			jContentPane.add(getJPasswordnewconfirm(), null);
			jContentPane.add(getJButtonOK(), null);
			jContentPane.add(getJButtonCancel(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jTextFieldusername	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextFieldusername() {
		if (jTextFieldusername == null) {
			jTextFieldusername = new JTextField();
			jTextFieldusername.setLocation(new Point(165, 30));
			jTextFieldusername.setSize(new Dimension(99, 20));
		}
		return jTextFieldusername;
	}

	/**
	 * This method initializes jPasswordold	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordold() {
		if (jPasswordold == null) {
			jPasswordold = new JPasswordField();
			jPasswordold.setLocation(new Point(165, 60));
			jPasswordold.setSize(new Dimension(99, 20));
		}
		return jPasswordold;
	}

	/**
	 * This method initializes jPasswordnew	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordnew() {
		if (jPasswordnew == null) {
			jPasswordnew = new JPasswordField();
			jPasswordnew.setLocation(new Point(165, 90));
			jPasswordnew.setSize(new Dimension(99, 20));
		}
		return jPasswordnew;
	}

	/**
	 * This method initializes jPasswordnewconfirm	
	 * 	
	 * @return javax.swing.JPasswordField	
	 */
	private JPasswordField getJPasswordnewconfirm() {
		if (jPasswordnewconfirm == null) {
			jPasswordnewconfirm = new JPasswordField();
			jPasswordnewconfirm.setSize(new Dimension(99, 20));
			jPasswordnewconfirm.setLocation(new Point(165, 120));
		}
		return jPasswordnewconfirm;
	}

	/**
	 * This method initializes jButtonOK	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButtonOK() {
		if (jButtonOK == null) {
			jButtonOK = new JButton();
			jButtonOK.setBounds(new Rectangle(60, 157, 65, 23));
			jButtonOK.setText("更新");
			jButtonOK.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					if(jTextFieldusername.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null, "用户名不能为空", "错误", JOptionPane.ERROR_MESSAGE);
						return;
					}
					if(jPasswordold.getText().trim().equals("")){
						JOptionPane.showMessageDialog(null, " 密码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
						return;
					}
					if(!jPasswordnewconfirm.getText().trim().equals(jPasswordnew.getText().trim())){
						JOptionPane.showMessageDialog(null, "两次输入的密码不一致", "错误", JOptionPane.ERROR_MESSAGE);
						return;
					}
					//检验用户名是否存在
					String strSQL;
					strSQL="select * from alluser where Username='"
						+jTextFieldusername.getText().trim()+"' and aPassword='"
						+jPasswordold.getText().trim()+"'";System.out.println(strSQL);
					rs=db.getResult(strSQL);
					boolean isexist=false;
					try{
						isexist=rs.first();						
					}
					catch(SQLException ex1){
						
					}
					
					if(!isexist){
						JOptionPane.showMessageDialog(null, " 用户名不存在,或原密码不正确", "错误", JOptionPane.ERROR_MESSAGE);
						jTextFieldusername.setText("");
						jPasswordold.setText("");
					}
					//若存在,执行更新操作
					else{
						strSQL="update alluser set aPassword='"+jPasswordnew.getText().trim()
						+"' where Username='"+jTextFieldusername.getText().trim()+"'";System.out.println(strSQL);
						//由数据库操作,并返回相关信息
						if(db.executeSql(strSQL)){
							JOptionPane.showMessageDialog(null, "更新成功", "成功", JOptionPane.INFORMATION_MESSAGE);
							buttonexit();
						}
						else{
							JOptionPane.showMessageDialog(null, " 更新失败,请重新操作", "错误", JOptionPane.ERROR_MESSAGE);
						}
					}
					/*catch(SQLException ex2){
						JOptionPane.showMessageDialog(null, " 用户名不存在,或原密码不正确", "错误", JOptionPane.ERROR_MESSAGE);
					}*/
				}
			});
		}
		return jButtonOK;
	}

	/**
	 * This method initializes jButtonCancel	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public void buttonexit(){
		this.dispose();
	}
	private JButton getJButtonCancel() {
		if (jButtonCancel == null) {
			jButtonCancel = new JButton();
			jButtonCancel.setLocation(new Point(169, 157));
			jButtonCancel.setText("取消");
			jButtonCancel.setSize(new Dimension(65, 23));
			jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
					buttonexit();
				}
			});
		}
		return jButtonCancel;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"

⌨️ 快捷键说明

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