package com.gui;
import java.awt.BorderLayout;
public class UpData extends JDialog implements ActionListener {
private final JPanel contentPanel = new JPanel();
private JTextField text_name;
private JPasswordField passwordField_old;
private JPasswordField passwordField_new;
private JPasswordField passwordField_re;
/**
* Launch the application.
* 密码修改界面
*/
public static void main(String[] args) {
try {
UpData dialog = new UpData();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Create the dialog.
*/
public UpData() {
setTitle("\u4FEE\u6539\u5BC6\u7801");
setResizable(false);
setBounds(450, 100, 472, 385);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
JLabel lblNewLabel = new JLabel("\u7528\u6237\u540D\uFF1A");
lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 20));
JLabel lblNewLabel_1 = new JLabel("\u65E7\u5BC6\u7801\uFF1A");
lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 20));
JLabel lblNewLabel_2 = new JLabel("\u65B0\u5BC6\u7801\uFF1A");
lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 20));
JLabel lblNewLabel_3 = new JLabel("\u786E\u5B9A\u5BC6\u7801\uFF1A");
lblNewLabel_3.setFont(new Font("宋体", Font.PLAIN, 20));
text_name = new JTextField();
text_name.setColumns(10);
passwordField_old = new JPasswordField();
passwordField_new = new JPasswordField();
passwordField_re = new JPasswordField();
JButton button_submit = new JButton("\u786E\u8BA4\u4FEE\u6539");
button_submit.setFont(new Font("宋体", Font.PLAIN, 15));
JButton button_exit = new JButton("\u53D6\u6D88\u4FEE\u6539");
button_exit.setFont(new Font("宋体", Font.PLAIN, 15));
button_submit.addActionListener(this); //注册监听
button_exit.addActionListener(this);
GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
gl_contentPanel.setHorizontalGroup(
gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addGap(71)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
.addComponent(button_submit)
.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(button_exit))
.addGroup(gl_contentPanel.createSequentialGroup()
.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_1)
.addComponent(lblNewLabel)
.addComponent(lblNewLabel_2)
.addComponent(lblNewLabel_3))
.addGap(9)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
.addComponent(passwordField_re)
.addComponent(passwordField_old)
.addComponent(text_name, GroupLayout.DEFAULT_SIZE, 188, Short.MAX_VALUE)
.addComponent(passwordField_new))))
.addContainerGap(67, Short.MAX_VALUE))
);
gl_contentPanel.setVerticalGroup(
gl_contentPanel.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPanel.createSequentialGroup()
.addGap(20)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel)
.addComponent(text_name, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(39)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_1)
.addComponent(passwordField_old, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
.addGap(32)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_2)
.addComponent(passwordField_new, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
.addGap(32)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
.addComponent(lblNewLabel_3)
.addComponent(passwordField_re, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
.addComponent(button_exit)
.addComponent(button_submit))
.addGap(37))
);
contentPanel.setLayout(gl_contentPanel);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String btnsString = e.getActionCommand();
if (btnsString.equals("确认修改")) {
System.out.print("确认修改");
String nameString = text_name.getText().trim();
String oldpassword = String.valueOf(passwordField_old.getPassword());
String newpassword = String.valueOf(passwordField_new.getPassword());
String repassword = String.valueOf(passwordField_re.getPassword());
//密码修改
if (!nameString.equals("")&&repassword.equals(newpassword)&& !repassword.equals("") && !newpassword.equals("")&& !oldpassword.equals("")) {
System.out.print("相同");
Userdate userdate = new Userdate();
String sql="update userdata set userpassword='"+newpassword+"' where username='"+nameString+"' and userpassword='"+oldpassword+"'";
boolean flag = userdate.updataUser(sql);
if (flag) {
JOptionPane.showMessageDialog(this, "密码修改成功!");
this.dispose();
}else {
JOptionPane.showMessageDialog(this,"用户名与密码不符,请重试!");
passwordField_old.setText("");
}
}else if(nameString.equals("")){
JOptionPane.showMessageDialog(this, "用户名不能为空!");
}else if (oldpassword.equals("")) {
JOptionPane.showMessageDialog(this, "请输入旧密码!");
}else if(newpassword.equals("")) {
JOptionPane.showMessageDialog(this, "新密码不能为空!");
System.out.print("新密码不能为空!");
}else if(repassword.equals("")) {
JOptionPane.showMessageDialog(this, "新密码不能为空!");
System.out.print("确认密码不能为空!");
}
else {
System.out.print("不相同");
JOptionPane.showMessageDialog(this, "确认密码与新密码不一致,请重新输入!");
passwordField_new.setText("");
passwordField_re.setText("");
}
}else {
System.out.print("取消");
this.dispose();
}
}
}
版权声明:本文为PCDHY123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。