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

📄 mychangepasswd.java

📁 一套基于JAVA开发的完整版航空订票系统,代码简洁,适合JAVA初学者研究
💻 JAVA
字号:
package com.tarena.abs.client;import java.awt.*;import java.awt.event.*;import javax.swing.*;import com.tarena.abs.model.Agent;import com.tarena.abs.model.Request;import com.tarena.abs.model.Response;public class MyChangePasswd extends JDialog implements ActionListener{	private static final long serialVersionUID = 523425844903633896L;	private JLabel label0,label1,label2,label3;	private JButton ok,cancel;	private JTextField t0;	private JPasswordField t1,t2,t3;	public MyChangePasswd(JFrame frame){		super(frame,"修改密码");		label0=new JLabel("用户名:");		label1=new JLabel("旧密码:");		label2=new JLabel("新密码:");		label3=new JLabel("重复新密码:");				t0=new JTextField(12);		t1=new JPasswordField(12);		t2=new JPasswordField(12);		t3=new JPasswordField(12);				ok=new JButton("修改");ok.addActionListener(this);		cancel=new JButton("取消");cancel.addActionListener(this);		init();		showMe();	}	public void init(){		JPanel p=new JPanel();		JPanel p1=new JPanel();		JPanel p2=new JPanel();		JPanel p3=new JPanel();		JPanel p4=new JPanel();		JPanel p5=new JPanel();		p1.setLayout(new FlowLayout(FlowLayout.LEFT));		p2.setLayout(new FlowLayout(FlowLayout.LEFT));		p3.setLayout(new FlowLayout(FlowLayout.LEFT));		p4.setLayout(new FlowLayout(FlowLayout.LEFT));		p1.add(label0);p1.add(t0);		p2.add(label1);p2.add(t1);		p3.add(label2);p3.add(t2);		p4.add(label3);p4.add(t3);				p5.setLayout(new FlowLayout(FlowLayout.LEFT));		p5.add(ok);p5.add(cancel);				p.setLayout(new GridLayout(4,1));		p.add(p1);		p.add(p2);		p.add(p3);		p.add(p4);			this.add(p,BorderLayout.CENTER);		this.add(p5,BorderLayout.SOUTH);			}			private void showMe(){		this.setSize(300,250);		this.setVisible(true);		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);//?	}	@SuppressWarnings({ "unchecked", "unchecked" })	public void actionPerformed(ActionEvent e){		if(e.getActionCommand().equals("修改")){//			判断文本框中的内容是否为空			if(t0.getText().equals("") || new String(t1.getPassword()).equals("") || new String(t2.getPassword()).equals("") || new String(t3.getPassword()).equals("")){				JOptionPane.showMessageDialog(this,"姓名和密码不能为空!");				t0.setText("");				t1.setText("");				t2.setText("");				t3.setText("");			}			//判断两次输入的密码是否一样			if(! new String(t2.getPassword()).equals(new String(t3.getPassword()))){				JOptionPane.showMessageDialog(this,"两次输入的密码不同!");				t0.setText("");				t1.setText("");				t2.setText("");				t3.setText("");			}			try {				//创建一个请求对象,该请求的类型为登录请求				Request req=new Request("changePW");				//向请求对象中添加数据				req.setData("UserName",t0.getText());				req.setData("OldPassword",new String(t1.getPassword()));				req.setData("NewPassworld", new String(t2.getPassword()));				//将请求对象写往服务器				ClientMainClass.oos.writeObject(req);				ClientMainClass.oos.flush();				//从服务器获得一个应答对象				Response res=(Response)ClientMainClass.ois.readObject();				//解析应答对象中封装的数据				Agent user=(Agent)res.getData();				//如果返回了一个合法的代理商(登录成功)				if(user!=null){					//把当前代理商对象保存成全局变量					ClientMainClass.currentUser=user;					JOptionPane.showMessageDialog(this,"修改成功!");					this.dispose();									}else{//如果登录不成功					JOptionPane.showMessageDialog(this,"对不起,修改失败,请重新输入!");					t0.setText("");					t1.setText("");					t2.setText("");					t3.setText("");				}			} catch (Exception e1) {				e1.printStackTrace();			}		}		if(e.getActionCommand().equals("取消")){			this.dispose();		}	}	}

⌨️ 快捷键说明

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