📄 changepasswd.java
字号:
package com.tarena.abs.client;import java.awt.BorderLayout;import java.awt.FlowLayout;import java.awt.GridLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField;import com.tarena.abs.model.Agent;import com.tarena.abs.model.Request;import com.tarena.abs.model.Response;public class ChangePasswd extends JDialog implements ActionListener{ /** * */ private static final long serialVersionUID = 1063440875822708352L; private JLabel label0,label1,label2,label3; private JButton ok,cancel; private JTextField t0; private JPasswordField t1,t2,t3; public ChangePasswd(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);//? } public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub if(e.getActionCommand().equals("修改")){ if(t0.getText().equals("")|| new String(t1.getPassword()).equals("")||new String(t2.getPassword()).equals("")){ JOptionPane.showMessageDialog(this,"您输入的信息不完整!"); t0.setText(""); t1.setText(""); t2.setText(""); t3.setText(""); return; } if(!new String(t2.getPassword()).equals(new String(t3.getPassword()))){ JOptionPane.showMessageDialog(this,"2次输入的密码不一致!"); t0.setText(""); t1.setText(""); t2.setText(""); t3.setText(""); return; }try { Request req=new Request("changePasswd"); req.setData("UserName",t0.getText()); req.setData("Password",new String(t1.getPassword())); req.setData("NewPasswd",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){ JOptionPane.showMessageDialog(this,"恭喜修改密码成功!"); this.dispose(); }else{ JOptionPane.showMessageDialog(this,"对不起,用户名和密码不正确,请重新输入!"); } } catch (Exception e1) { e1.printStackTrace(); } }else if(e.getActionCommand().equals("取消")){ this.dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -