📄 userdelete.java
字号:
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import javax.swing.*;
public class UserDelete extends JFrame implements ActionListener{
DataBaseManager db=new DataBaseManager();
ResultSet rs;
JLabel jLabel1;
JLabel jLabel2;
JButton jButton2;
private JLabel jLabel4;
private JLabel jLabel3;
JButton jButton1;
JPasswordField jPasswordField1;
JTextField jTextField1;
public UserDelete(){
this.setTitle("删除用户");
this.setVisible(true);
this.setResizable(false);
this.setBounds(431, 223, 345, 191);
this.setLayout(null);
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("用户名:");
jLabel1.setBounds(18, 89, 47, 15);
}
{
jTextField1 = new JTextField();
getContentPane().add(jTextField1);
jTextField1.setText("");
jTextField1.setBounds(77, 84, 146, 24);
}
{
jLabel2 = new JLabel();
getContentPane().add(jLabel2);
jLabel2.setText("密码:");
jLabel2.setBounds(24, 125, 53, 15);
}
{
jPasswordField1 = new JPasswordField();
getContentPane().add(jPasswordField1);
jPasswordField1.setEchoChar('*');
jPasswordField1.setText("");
jPasswordField1.setBounds(77, 120, 146, 25);
}
{
jButton1 = new JButton();
jButton1.addActionListener(this);
getContentPane().add(jButton1);
jButton1.setText("确定");
jButton1.setBounds(241, 85, 62, 22);
}
{
jButton2 = new JButton();
jButton2.addActionListener(this);
getContentPane().add(jButton2);
jButton2.setText("取消");
jButton2.setBounds(241, 113, 61, 22);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3.setText("jLabel3");
jLabel3.setIcon(new ImageIcon(getClass().getClassLoader().getResource("logina.jpg")));
jLabel3.setBounds(0, -4, 406, 80);
}
{
jLabel4 = new JLabel();
getContentPane().add(jLabel4);
jLabel4.setText("jLabel4");
jLabel4.setIcon(new ImageIcon(getClass().getClassLoader().getResource("mww.jpg")));
jLabel4.setBounds(-76, 19, 1326, 700);
}
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jButton2)
{
this.dispose();
}
else if(e.getSource()==jButton1)
{
try
{
String strSQL="select * from [user1] where UserName='"+
jTextField1.getText().trim()+"' and PassWord='"+
"'";
if( jTextField1.getText().trim().equals(""))
{
JOptionPane.showMessageDialog(null,"用户名不能为空!");
}
else if(jPasswordField1.equals(""))
{
JOptionPane.showMessageDialog(null,"密码不能为空!");
}
else if(db.getResult(strSQL).first())
{
strSQL="delete from [user1] where UserName='"+
jTextField1.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 + -