📄 updatepwd.java
字号:
package edu.sccp.chat.frame;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.BorderFactory;
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.swtdesigner.SwingResourceManager;
import edu.sccp.chat.action.ToServerProcess;
import edu.sccp.chat.jarClass.JarAllege;
import edu.sccp.chat.tools.Check;
public class UpdatePwd {
public static JTextField nametextField;
/**
* @param args
*/
JFrame frame;
JPanel panel;
JLabel label;
JLabel label_8;
JLabel label_9;
public static JTextField textField;
public static JButton commit;
public UpdatePwd()
{
JarAllege.bai();
initGUI();
}
private void initGUI()
{
frame=new JFrame("修改用户密码");
frame.setIconImage(SwingResourceManager.getImage(UpdatePwd.class, "/edu/sccp/chat/image/icon.png"));
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(final WindowEvent e) {
frame.dispose();
}
});
frame.getContentPane().setLayout(null);
panel = new JPanel();
panel.setLayout(null);
panel.setBorder(BorderFactory.createTitledBorder("根据ID修改密码"));
panel.setBounds(10, 10, 257, 151);
frame.getContentPane().add(panel);
final JLabel idLabel_1 = new JLabel();
idLabel_1.setText("ID:");
idLabel_1.setBounds(43, 34, 42, 18);
panel.add(idLabel_1);
textField = new JTextField();
textField.addKeyListener(new KeyAdapter() {
public void keyPressed(final KeyEvent e) {
if(e.getKeyCode()==KeyEvent.VK_ENTER){
if(!Check.checkMsg(textField.getText(), 8, 10,true)){
JOptionPane.showMessageDialog(frame, "ID号必须为数字,8-10位", "Warning", JOptionPane.WARNING_MESSAGE);
textField.setText("");
}
try {
ToServerProcess.oos.writeObject("密码用户");
String id=textField.getText().trim();
ToServerProcess.oos.writeObject(id);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
textField.setBounds(77, 35, 98, 18);
panel.add(textField);
final JLabel label_1 = new JLabel();
label_1.setText("新密码:");
label_1.setBounds(23, 85, 65, 18);
panel.add(label_1);
final JPasswordField passwordField = new JPasswordField();
passwordField.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent e) {
if(passwordField.getText().length()==0)
{
label_8.setText("6-10之内");
}else
label_8.setText("");
}
public void focusLost(final FocusEvent e) {
if(passwordField.getText().length()==0)
{
label_8.setText("不能为空");
}else
label_8.setText("");
}
});
passwordField.setBounds(77, 86, 98, 18);
panel.add(passwordField);
final JLabel label_2 = new JLabel();
label_2.setText("重复密码:");
label_2.setBounds(6, 115, 65, 18);
panel.add(label_2);
final JPasswordField passwordFieldTwo = new JPasswordField();
passwordFieldTwo.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent e) {
if(passwordFieldTwo.getText().length()==0)
{
label_9.setText("6-10之内");
}else
label_9.setText("");
}
public void focusLost(final FocusEvent e) {
if(passwordFieldTwo.getText().length()==0)
{
label_9.setText("不能为空");
}else
label_9.setText("");
}
});
passwordFieldTwo.setBounds(77, 116, 99, 18);
panel.add(passwordFieldTwo);
label_8 = new JLabel();
label_8.setForeground(new Color(255, 0, 0));
label_8.setBounds(182, 87, 60, 15);
panel.add(label_8);
label_9 = new JLabel();
label_9.setForeground(new Color(255, 0, 0));
label_9.setBounds(182, 117, 60, 15);
panel.add(label_9);
label = new JLabel();
label.setText("输完按回车");
label.setBounds(182, 36, 75, 15);
panel.add(label);
label.setForeground(new Color(0, 0, 0));
final JLabel label_3 = new JLabel();
label_3.setText("姓名:");
label_3.setBounds(28, 61, 60, 15);
panel.add(label_3);
nametextField = new JTextField();
nametextField.setEditable(false);
nametextField.setBounds(77, 59, 98, 20);
panel.add(nametextField);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
frame.dispose();
}
});
button.setText("关闭");
button.setBounds(198, 167, 69, 25);
frame.getContentPane().add(button);
final JButton button_3 = new JButton();
button_3.setBounds(124, 167, 68, 25);
frame.getContentPane().add(button_3);
button_3.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
nametextField.setText("");
textField.setText("");
textField.setEditable(true);
commit.setEnabled(false);
}
});
button_3.setText("重置");
commit = new JButton();
commit.setBounds(49, 167, 69, 26);
frame.getContentPane().add(commit);
commit.setEnabled(false);
commit.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
if(textField.getText().length()==0)
{
JOptionPane.showMessageDialog(frame,"ID不能为空!","警告",JOptionPane.WARNING_MESSAGE,null);
return;
}else
{
if(!(Check.checkMsg(textField.getText(),8,10,true)))
{
JOptionPane.showMessageDialog(frame,"ID长度不在范围之内,请保持输入在8-10之内!","警告",JOptionPane.WARNING_MESSAGE,null);
textField.setText("");
return;
}
}
if(passwordField.getText().length()==0)
{
JOptionPane.showMessageDialog(frame,"新密码不能为空!","警告",JOptionPane.WARNING_MESSAGE,null);
return;
}
else
{
if(!(Check.checkMsg(passwordField.getText(), 6, 10, false)))
{
JOptionPane.showMessageDialog(frame,"输入的新密码不符合长度!","警告",JOptionPane.WARNING_MESSAGE,null);
passwordField.setText("");
return;
}
}
if(passwordFieldTwo.getText().length()==0)
{
JOptionPane.showMessageDialog(frame,"重复密码不能为空!","警告",JOptionPane.WARNING_MESSAGE,null);
return;
}
else
{
if(!(Check.checkMsg(passwordFieldTwo.getText(), 6, 10, false)))
{
JOptionPane.showMessageDialog(frame,"输入的重复密码不符合长度!","警告",JOptionPane.WARNING_MESSAGE,null);
passwordFieldTwo.setText("");
return;
}
}
if(!passwordField.getText().equals(passwordFieldTwo.getText()))
{
JOptionPane.showMessageDialog(frame,"重复密码和新密码不同!","警告",JOptionPane.WARNING_MESSAGE,null);
passwordField.setText("");
passwordFieldTwo.setText("");
return;
}
try {
ToServerProcess.oos.writeObject("修改用户密码");
String id=textField.getText().trim();
ToServerProcess.oos.writeObject(id);
String pwd=passwordField.getText().trim();
ToServerProcess.oos.writeObject(pwd);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
commit.setText("提交");
}
public void showGUI()
{
frame.setResizable(false);
frame.setSize(283,227);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new UpdatePwd().showGUI();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -