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

📄 updatepwddialog.java

📁 用java开发的QQ管理系统
💻 JAVA
字号:
package com.zlf.qqclient.mainframe.updatepwd;
/**
 * 设置密码对话框
 * @author zlf
 */
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;

import com.zlf.qq.pub.DataPacket;
import com.zlf.qqclient.utils.Public;

public class updatePwdDialog extends JDialog {

	/**
	 * 
	 * 设置密码对话框.
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private JPanel mainPane;
	private JPasswordField old;
	private JPasswordField newPwd;
	private JPasswordField reNewPwd;
	public updatePwdDialog(final String userId) {
		this.setSize(new Dimension(340, 180));
		this.setTitle("修改密码");
		this.setLocationRelativeTo(null);
		mainPane = new JPanel();
		/**
		 * 界面布局
		 */
		Box box1 = Box.createHorizontalBox();
		box1.add(new JLabel("原始密码:"));
		box1.add(Box.createHorizontalStrut(10));
		old = new JPasswordField();
		old.setEchoChar('*');
		box1.add(old);
		Box box2 = Box.createHorizontalBox();
		box2.add(new JLabel("新 密 码:"));
		box2.add(Box.createHorizontalStrut(10));
		newPwd = new JPasswordField();
		newPwd.setEchoChar('*');
		box2.add(newPwd);
		Box box3 = Box.createHorizontalBox();
		box3.add(new JLabel("确认密码:"));
		box3.add(Box.createHorizontalStrut(10));
		reNewPwd = new JPasswordField();
		reNewPwd.setEchoChar('*');
		box3.add(reNewPwd);
		Box box4 = Box.createHorizontalBox();
		JButton ok = new JButton("确认");
		ok.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				String oldPwd=String.valueOf(old.getPassword());
				System.out.println(oldPwd);
				System.out.println(Public.finalUserPwd);
				String strNew=String.valueOf(newPwd.getPassword());
				String strreNewPwd=String.valueOf(reNewPwd.getPassword());
				if ( !oldPwd.equals("") &&!strNew.equals("")&& !strreNewPwd.equals("")){
					if (oldPwd.equals(Public.finalUserPwd)){
						if (strNew.equals(strreNewPwd)) {
							// 如果两次新密码输入一致,原始密码输入正确的时候发送修改密码到服务器
							HashMap data = new HashMap();
							data.put("newPwd", String.valueOf(newPwd.getPassword()));
							DataPacket updatePwd =new DataPacket(DataPacket.UPDATE_PWD, userId, "", data);
							ArrayList a = (ArrayList) Public.mySocketInfo.get(userId);
							ObjectOutputStream oos=(ObjectOutputStream) a.get(2);
							try {
								oos.writeObject(updatePwd);
								oos.flush();
								//释放掉对话框
								updatePwdDialog.this.dispose();
								JOptionPane.showMessageDialog(mainPane,
										"密码修改成功!", "提示框",
										JOptionPane.WARNING_MESSAGE);
							} catch (IOException e1) {
								e1.printStackTrace();
							}
						} else {
							JOptionPane.showMessageDialog(mainPane,
									"新密码两次输入不一致,请重新输入!", "提示框",
									JOptionPane.WARNING_MESSAGE);
							newPwd.setText("");
							reNewPwd.setText("");
							newPwd.setFocusable(true);
						}
					}else {
						JOptionPane.showMessageDialog(mainPane,
								"原始密码输入错误,请重新输入!", "提示框",
								JOptionPane.WARNING_MESSAGE);
						old.setFocusable(true);
					}
				}else{
					JOptionPane.showMessageDialog(mainPane,
							"原始密码新密码都不能为空,请输入!", "提示框",
							JOptionPane.WARNING_MESSAGE);
					old.setFocusable(true);
				}
			}

		});
		box4.add(ok);
		box4.add(Box.createHorizontalStrut(30));
		JButton cancel=new JButton("取消");
		cancel.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e) {
				updatePwdDialog.this.dispose();
			}
			
		});
		box4.add(cancel);
		
		mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
		mainPane.add(box1);
		mainPane.add(Box.createVerticalStrut(5));
		mainPane.add(box2);
		mainPane.add(Box.createVerticalStrut(5));
		mainPane.add(box3);
		mainPane.add(Box.createVerticalStrut(5));
		mainPane.add(box4);
		mainPane.setBorder(BorderFactory.createEmptyBorder(20, 30, 20, 30));
		mainPane.setBackground(new Color(200, 230, 220));
		this.getContentPane().add(mainPane);

	}

}

⌨️ 快捷键说明

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