📄 studelete.java
字号:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class StuDelete extends JFrame implements ActionListener {
DataBaseManager db = new DataBaseManager();
JButton jButton2;
JTextField jTextField2;
JLabel jLabel1;
JToolBar jToolBar1;
JLabel jLabel3;
JButton jButton3;
JButton jButton1;
ResultSet rs;
public StuDelete(){
this.setTitle("删除学生信息");
this.setLayout(null);
this.setBounds(431, 223, 285, 179);
this.setResizable(false);
this.setVisible(true);
{
jButton1 = new JButton();
jButton1.addActionListener(this);
getContentPane().add(jButton1);
jButton1.setText("删除");
jButton1.setBounds(20, 93, 66, 22);
}
{
jButton2 = new JButton();
jButton2.addActionListener(this);
getContentPane().add(jButton2);
jButton2.setText("查看");
jButton2.setBounds(107, 93, 64, 22);
}
{
jButton3 = new JButton();
jButton3.addActionListener(this);
getContentPane().add(jButton3);
jButton3.setText("取消");
jButton3.setBounds(194, 93, 64, 22);
}
{
jLabel3 = new JLabel();
getContentPane().add(jLabel3);
jLabel3 .setForeground(Color.RED);
jLabel3.setText(" 按学号进行删除!");
jLabel3.setBounds(27, 6, 139, 24);
}
{
jToolBar1 = new JToolBar();
getContentPane().add(jToolBar1);
jToolBar1.setBounds(2, 0, 320, 28);
}
{
jLabel1 = new JLabel();
getContentPane().add(jLabel1);
jLabel1.setText("学号:");
jLabel1.setBounds(33, 41, 41, 15);
}
{
jTextField2 = new JTextField();
getContentPane().add(jTextField2);
jTextField2.setText("");
jTextField2.setBounds(86, 36, 130, 25);
}
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jButton3){
this.dispose();
}
else if(e.getSource()==jButton2){
StuList StuListFrame=new StuList();
Dimension FrameSize=StuListFrame.getPreferredSize();
Dimension MainFrameSize=getSize();
Point loc=getLocation();
StuListFrame.setLocation((MainFrameSize.width-FrameSize.width)/2+loc.x,
(MainFrameSize.height-FrameSize.height)/2+loc.y);
StuListFrame.pack();
StuListFrame.show();
}
else if(e.getSource()==jButton1){
try
{
String strSQL="select * from xs where 学号='"+
jTextField2.getText().trim()+"'";
if (jTextField2.getText().trim().equals("")) {
JOptionPane.showMessageDialog(null, "学号不能为空!");
}
else if(db.getResult(strSQL).first())
{
strSQL="delete from xs where 学号='"+
jTextField2.getText().trim()+"'";
if(db.updateSql(strSQL))
{
int result=JOptionPane.showOptionDialog(null, "学生的基本信息删除成功是否返回删除界面删除其他学生的信息?", "系统提示", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, new String[] {"是","否"}, "否");
if(result==JOptionPane.YES_OPTION){
new StuDelete();
this.dispose();
}
else{
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 + -