📄 useredit.java
字号:
import javax.swing.*;
import java.awt.event.*;
import java.awt.GridLayout;
import java.sql.*;
public class userEdit extends JFrame implements ActionListener
{
public userEdit()
{
setTitle("修改用户");
setSize(200,200);
gl=new GridLayout(5,2,20,20);
JPanel panel=new JPanel();
panel.setLayout(gl);
userlbl=new JLabel("用户名");
oldpasswordlbl=new JLabel("原密码");
confirmlbl=new JLabel("确认新密码");
newpasswordlbl=new JLabel("新密码");
usertex=new JTextField("");
oldpasswordtex=new JPasswordField("");
newpasswordtex=new JPasswordField("");
confirmtex=new JPasswordField("");
addbtn=new JButton("确认");
cancelbtn=new JButton("取消");
panel.add(userlbl);
panel.add(usertex);
panel.add(oldpasswordlbl);
panel.add(oldpasswordtex);
panel.add(newpasswordlbl);
panel.add(newpasswordtex);
panel.add(confirmlbl);
panel.add(confirmtex);
panel.add(addbtn);
panel.add(cancelbtn);
getContentPane().add(panel);
addbtn.addActionListener(this);
cancelbtn.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source=e.getSource();
if(source==addbtn)
{
String username=new String(usertex.getText()).trim();
if(username.equals(""))
{
JOptionPane.showMessageDialog(null,"用户名不能为空!");
return;
}
String password=new String(oldpasswordtex.getText()).trim();
if(password.equals(""))
{
JOptionPane.showMessageDialog(null,"密码不能为空!");
return;
}
String pass=new String(newpasswordtex.getText()).trim();
if(pass.equals(""))
{
JOptionPane.showMessageDialog(null,"新密码不能为空!");
return;
}
String con=new String(confirmtex.getText()).trim();
if(con.equals(""))
{
JOptionPane.showMessageDialog(null,"密码不一致!");
return;
}
if(con.equals("")||!(con.equals(pass)))
{
confirmtex.setText("");
oldpasswordtex.setText("");
newpasswordtex.setText("");
JOptionPane.showMessageDialog(null,"密码不一样");
return;
}
String strsql;
strsql=("update 读者权限表 set 密码='"+pass+"' where 用户名='"+username+"' and 密码='"+password+"'");
System.out.println(strsql);
boolean success=db.executeSql(strsql);
if(!success)
{
JOptionPane.showMessageDialog(null,"修改不成功,请重试");
}
else
{
JOptionPane.showMessageDialog(null,"修改成功");
this.dispose();
}
}
if(source==cancelbtn)
{
this.dispose();
return;
}
}
private JLabel userlbl;
private JLabel oldpasswordlbl;
private JLabel newpasswordlbl;
private JLabel confirmlbl;
private JTextField usertex;
private JPasswordField oldpasswordtex;
private JPasswordField confirmtex;
private JPasswordField newpasswordtex;
private JButton addbtn;
private JButton cancelbtn;
private GridLayout gl;
private ResultSet rs;
private DBManager db=new DBManager();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -