📄 userdelete.java
字号:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class UserDelete extends JFrame implements ActionListener
{
DataBaseManager db=new DataBaseManager();
ResultSet rs;
JPanel panel1,panel2;
Container c;
JLabel UserLabel,PasswordLabel;
JTextField UserTextField;
JPasswordField PasswordTextField;
JButton YesBtn,CancelBtn;
public UserDelete()
{
super("删除用户");
c=getContentPane();
c.setLayout(new BorderLayout());
UserLabel=new JLabel("用户名",JLabel.CENTER);
PasswordLabel=new JLabel("密码",JLabel.CENTER);
UserTextField=new JTextField(10);
PasswordTextField=new JPasswordField(10);
YesBtn=new JButton("确定");
CancelBtn=new JButton("取消");
YesBtn.addActionListener(this);
CancelBtn.addActionListener(this);
panel1=new JPanel();
panel1.setLayout(new GridLayout(2,2));
panel1.add(UserLabel);
panel1.add(UserTextField);
panel1.add(PasswordLabel);
panel1.add(PasswordTextField);
panel2=new JPanel();
panel2.add(YesBtn);
panel2.add(CancelBtn);
c.add(panel1,BorderLayout.CENTER);
c.add(panel2,BorderLayout.SOUTH);
setSize(300,300);
}
public void actionPerformed(ActionEvent e)
{
try
{
if(e.getSource()==CancelBtn)
{
db.closeConnection();
this.dispose();
}
else if(e.getSource()==YesBtn)
{
char[] password=PasswordTextField.getPassword();
String passwordSTR=new String(password);
String strSQL="select * from userTable where userName='"+
UserTextField.getText().trim()+"' and password='"+
passwordSTR+"'";
if(UserTextField.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"用户名不能为空!");
}
else if(PasswordTextField.equals(""))
{
JOptionPane.showMessageDialog(null,"密码不能为空!");
}
else if(db.getResult(strSQL).first())
{
strSQL="delete from userTable where userName='"+
UserTextField.getText().trim()+"'";
if(db.updateSql(strSQL))
{
JOptionPane.showMessageDialog(null,"删除成功!");
this.dispose();
}
else
{
JOptionPane.showMessageDialog(null,"删除失败!");
this.dispose();
}
db.closeConnection();
}
else
{
JOptionPane.showMessageDialog(null,"不存在此用户或者密码错误!");
}
}
}
catch(SQLException sqle)
{
System.out.println(sqle.toString());
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -