java中密码修改

package com.gui;

import java.awt.BorderLayout;
public class UpData extends JDialog implements ActionListener {

	private final JPanel contentPanel = new JPanel();
	private JTextField text_name;
	private JPasswordField passwordField_old;
	private JPasswordField passwordField_new;
	private JPasswordField passwordField_re;
	
	
	/**
	 * Launch the application.
	 * 密码修改界面
	 */
	public static void main(String[] args) {
		try {
			UpData dialog = new UpData();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public UpData() {
		setTitle("\u4FEE\u6539\u5BC6\u7801");
		setResizable(false);
		setBounds(450, 100, 472, 385);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
		JLabel lblNewLabel_1 = new JLabel("\u65E7\u5BC6\u7801\uFF1A");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
		JLabel lblNewLabel_2 = new JLabel("\u65B0\u5BC6\u7801\uFF1A");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 20));
		JLabel lblNewLabel_3 = new JLabel("\u786E\u5B9A\u5BC6\u7801\uFF1A");
		lblNewLabel_3.setFont(new Font("宋体", Font.PLAIN, 20));
		text_name = new JTextField();
		text_name.setColumns(10);
		passwordField_old = new JPasswordField();
		passwordField_new = new JPasswordField();
		passwordField_re = new JPasswordField();
		JButton button_submit = new JButton("\u786E\u8BA4\u4FEE\u6539");
		button_submit.setFont(new Font("宋体", Font.PLAIN, 15));
		JButton button_exit = new JButton("\u53D6\u6D88\u4FEE\u6539");
		button_exit.setFont(new Font("宋体", Font.PLAIN, 15));
		
		button_submit.addActionListener(this); //注册监听
		button_exit.addActionListener(this);
		
		
		
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(71)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
						.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
							.addComponent(button_submit)
							.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
							.addComponent(button_exit))
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel_1)
								.addComponent(lblNewLabel)
								.addComponent(lblNewLabel_2)
								.addComponent(lblNewLabel_3))
							.addGap(9)
							.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
								.addComponent(passwordField_re)
								.addComponent(passwordField_old)
								.addComponent(text_name, GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
								.addComponent(passwordField_new))))
					.addContainerGap(67, Short.MAX_VALUE))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(20)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(text_name, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
					.addGap(39)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_1)
						.addComponent(passwordField_old, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addGap(32)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_2)
						.addComponent(passwordField_new, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addGap(32)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel_3)
						.addComponent(passwordField_re, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
					.addPreferredGap(ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(button_exit)
						.addComponent(button_submit))
					.addGap(37))
		);
		contentPanel.setLayout(gl_contentPanel);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		String btnsString = e.getActionCommand();
		
		if (btnsString.equals("确认修改")) {			
			System.out.print("确认修改");
			String nameString = text_name.getText().trim();	
			String oldpassword = String.valueOf(passwordField_old.getPassword());
			
			String newpassword = String.valueOf(passwordField_new.getPassword());
			String repassword = String.valueOf(passwordField_re.getPassword());
			
			//密码修改
			
			
			if (!nameString.equals("")&&repassword.equals(newpassword)&& !repassword.equals("") && !newpassword.equals("")&& !oldpassword.equals("")) {
				System.out.print("相同");
				Userdate userdate = new Userdate();
				String sql="update userdata set userpassword='"+newpassword+"' where username='"+nameString+"' and userpassword='"+oldpassword+"'";
				boolean flag = userdate.updataUser(sql);
				if (flag) {
					JOptionPane.showMessageDialog(this, "密码修改成功!");
					this.dispose();
				}else {
					JOptionPane.showMessageDialog(this,"用户名与密码不符,请重试!");
					passwordField_old.setText("");
				}							
				
			}else if(nameString.equals("")){
				JOptionPane.showMessageDialog(this, "用户名不能为空!");
			}else if (oldpassword.equals("")) {
				JOptionPane.showMessageDialog(this, "请输入旧密码!");
			}else if(newpassword.equals("")) {
				JOptionPane.showMessageDialog(this, "新密码不能为空!");
				System.out.print("新密码不能为空!");
			}else if(repassword.equals("")) {
				JOptionPane.showMessageDialog(this, "新密码不能为空!");
				System.out.print("确认密码不能为空!");
			}
			else {
				System.out.print("不相同");
				JOptionPane.showMessageDialog(this, "确认密码与新密码不一致,请重新输入!");
				passwordField_new.setText("");
				passwordField_re.setText("");
			}
			
			
		}else {
			System.out.print("取消");
			this.dispose();
		}
		
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值