📄 usereditdialog.java
字号:
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
class UserEditDialog implements ActionListener
{
private JTextField userName,password,passwordConfirm,account,shopName;
private JDialog dialog;
private BufferedReader in;
private PrintWriter out;
private int userID;
public UserEditDialog(JFrame f,User u,BufferedReader fin,PrintWriter fout)
{
in = fin;
out = fout;
userID = u.getId();
dialog = new JDialog(f,"更新个人信息",true);
dialog.setResizable(false);
JPanel textPanel = new JPanel();
textPanel.setLayout(new GridBagLayout());
textPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray,2),
"请填写新的个人信息",TitledBorder.CENTER,TitledBorder.TOP));
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(2,2,2,2);
JLabel l1 = new JLabel("用户名(*):");
JLabel l2 = new JLabel("密码(*):");
JLabel l3 = new JLabel("密码确认(*):");
JLabel l4 = new JLabel("帐户号码(*):");
JLabel l5 = new JLabel("地址:");
JLabel l6 = new JLabel("电子邮箱:");
userName = new JTextField(12);
userName.setText(u.getUserName());
password = new JTextField(12);
password.setText(u.getPassword());
passwordConfirm = new JTextField(12);
passwordConfirm.setText(u.getPassword());
account = new JTextField(12);
account.setText(u.getAccount()+"");
gbc.gridy=1;
gbc.gridx=0;
textPanel.add(l1,gbc);
gbc.gridx=1;
textPanel.add(userName,gbc);
gbc.gridy=2;
gbc.gridx=0;
textPanel.add(l2,gbc);
gbc.gridx=1;
textPanel.add(password,gbc);
gbc.gridy=3;
gbc.gridx=0;
textPanel.add(l3,gbc);
gbc.gridx=1;
textPanel.add(passwordConfirm,gbc);
gbc.gridy=4;
gbc.gridx=0;
textPanel.add(l4,gbc);
gbc.gridx=1;
textPanel.add(account,gbc);
gbc.gridy=5;
gbc.gridx=0;
textPanel.add(l5,gbc);
gbc.gridx=1;
textPanel.add(new JTextField(12),gbc);
gbc.gridy=6;
gbc.gridx=0;
textPanel.add(l6,gbc);
gbc.gridx=1;
textPanel.add(new JTextField(12),gbc);
JPanel buttonPanel=new JPanel();
JButton b=new JButton("确定");
b.addActionListener(this);
buttonPanel.add(b);
b=new JButton("取消");
b.addActionListener(this);
buttonPanel.add(b);
dialog.add(textPanel,BorderLayout.CENTER);
dialog.add(buttonPanel,BorderLayout.SOUTH);
dialog.setBounds(382,200,260,300);
dialog.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String cmd=e.getActionCommand();
if (cmd.equals("确定"))
{
boolean legal=true;
if(userName.getSelectionEnd()==0 ||password.getSelectionEnd()==0 || passwordConfirm.getSelectionEnd()==0 || account.getSelectionEnd()==0)
{
legal = false;
JOptionPane.showMessageDialog(null," 请填写完整!","填写信息不正确",2);
}
else if(!password.getText().equals(passwordConfirm.getText()) )
{
legal = false;
JOptionPane.showMessageDialog(null," 两次输入的密码不相同!","填写信息不正确",2);
}
else if(password.getText().length()<6 ||password.getText().length()>20 )
{
legal = false;
JOptionPane.showMessageDialog(null," 密码长度不符合规则!","填写信息不正确",2);
}
else if(userName.getText().length()>12)
{
legal = false;
JOptionPane.showMessageDialog(null," 用户名过长!","填写信息不正确",2);
}
else
{
char[] temp = userName.getText().toCharArray();
for(int i=0;i<userName.getText().length();i++)
{
if(!((temp[i]>='0'&&temp[i]<='9')||(temp[i]>='a'&&temp[i]<='z')||(temp[i]>='A'&&temp[i]<='Z')||(temp[i]=='_')))
{
legal = false;
JOptionPane.showMessageDialog(null," 用户名填写不符合规则!","填写信息不正确",2);
return;
}
}
temp = password.getText().toCharArray();
for(int i=0;i<password.getText().length();i++)
{
if(!((temp[i]>='0'&&temp[i]<='9')||(temp[i]>='a'&&temp[i]<='z')||(temp[i]>='A'&&temp[i]<='Z')))
{
legal = false;
JOptionPane.showMessageDialog(null," 密码填写不符合规则!","填写信息不正确",2);
return;
}
}
temp = account.getText().toCharArray();
for(int i=0;i<account.getText().length();i++)
{
if(!((temp[i]>='0'&&temp[i]<='9')))
{
legal = false;
JOptionPane.showMessageDialog(null," 帐户号填写不符合规则!","填写信息不正确",2);
return;
}
}
}
if(legal)
{
try
{
out.println("UPDATEUSER");
out.println(userID);
out.println(userName.getText());
out.println(password.getText());
out.println(account.getText());
String result = in.readLine();
if(result.equals("USED"))
{
out.println(JOptionPane.showInputDialog(null,"该账户已存在!","请输入拥有该账户的用户名"));
result = in.readLine();
}
if(result.equals("SUCCESS"))
{
JOptionPane.showMessageDialog(null,userName.getText()+": 已成功修改个人信息!","更新成功",1);
dialog.dispose();
}
if(result.equals("FAILURE"))
{
JOptionPane.showMessageDialog(null," 该用户名已存在,请重新选择用户名!","更新失败",0);
}
if(result.equals("ERROR"))
{
JOptionPane.showMessageDialog(null," 系统更新信息失败!","更新失败",0);
}
if(result.equals("AFAILURE"))
{
JOptionPane.showMessageDialog(null,"账户信息输入不正确,请重新选择账户号码!","更新失败",0);
}
}catch(Exception ex){}
}
}
else if (cmd.equals("取消"))
{
dialog.dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -