📄 delfrom.java
字号:
package testsystem;
import java.awt.*;
import java.sql.*;
import javax.swing.*;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class DelFrom extends JFrame {
private ImageIcon im1 = new ImageIcon("img\\red_forum.gif");
public DelFrom() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
this.getContentPane().setBackground(new Color(226, 176, 226));
this.setResizable(false);
setTitle("删除用户!");
getContentPane().setLayout(null);
jButton1.setBounds(new Rectangle(142, 199, 110, 36));
jButton1.setIcon(im1);
jButton1.setText("删除");
jButton1.addActionListener(new DelFrom_jButton1_actionAdapter(this));
this.getContentPane().add(jButton1);
jLabel2.setForeground(Color.red);
jLabel2.setText("删除用户后如想恢复请在“添加用户”里添加!");
jLabel2.setBounds(new Rectangle(65, 133, 252, 37));
jLabel1.setText("请输入要删除的用户名:");
jLabel1.setBounds(new Rectangle(125, 33, 132, 35));
this.getContentPane().add(jLabel1);
this.getContentPane().add(jt1);
this.getContentPane().add(jLabel2);
jt1.setBounds(new Rectangle(97, 81, 192, 34));
}
public static void main(String[] args) {
DelFrom delfrom = new DelFrom();
}
JButton jButton1 = new JButton();
JTextField jt1 = new JTextField();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
//删除用户功能
public void jButton1_actionPerformed(ActionEvent e) {
String Name=jt1.getText().trim();
Connection con=null;
Statement s1=null;
ResultSet rs=null;
if(Name.length()!=0)
{
try
{
con=DBcon.link();
s1=con.createStatement();
rs=s1.executeQuery("select * from Login where Name='"+Name+"'");//查询表中Name里是否存在用户!
if(rs.next())
{
JOptionPane.showMessageDialog(null,"用户存在可以删除!");
s1.executeUpdate("delete from Login where Name='"+Name+"'"); //如果存在可以删除!
JOptionPane.showMessageDialog(null,"删除成功!");
int p=JOptionPane.showConfirmDialog(null,"您还要继续删除吗?","提示",JOptionPane.YES_NO_OPTION);
if(p!=0)
{
this.setVisible(false);
}
else
{
jt1.setText("");
jt1.requestFocus();
return;
}
}
else
{
JOptionPane.showMessageDialog(null,"没有这个用户,请重新输入!","提示",JOptionPane.ERROR_MESSAGE);
jt1.setText("");
jt1.requestFocus();
}
}
catch(SQLException ce)
{
JOptionPane.showMessageDialog(null,ce.getMessage());
}
}
else
{
JOptionPane.showMessageDialog(null,"用户名不能为空!","提示",JOptionPane.ERROR_MESSAGE);
}
}
}
class DelFrom_jButton1_actionAdapter implements ActionListener {
private DelFrom adaptee;
DelFrom_jButton1_actionAdapter(DelFrom adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -