⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 delete.java

📁 java实现简易的教学管理系统
💻 JAVA
字号:
import java.awt.*;import javax.swing.*;import java.sql.*;import java.awt.event.*;public class Delete extends JFrame implements ActionListener{   JButton yesB,cancelB;   JTextField text1;   String SNO;   MainWindow parent3;  public Delete(MainWindow f3){    parent3=f3;    Container c=this.getContentPane();    c.setLayout(new GridLayout(3,1));    c.setFont(new Font("true",Font.TRUETYPE_FONT,13));    JPanel p1=new JPanel();    JPanel p2=new JPanel();    //    JLabel label1=new JLabel("删除学生信息",SwingConstants.CENTER);    label1.setFont(new Font("TRUE",Font.TRUETYPE_FONT,25));    label1.setForeground(Color.red);    c.add(label1);    //设置对话框    JLabel label2=new JLabel("请输入学生号");    text1=new JTextField(10);    p1.add(label2);    p1.add(text1);    c.add(p1);    //设置按钮     yesB=new JButton("确定");     cancelB=new JButton("退出");    p2.add(yesB);    p2.add(cancelB);    c.add(p2);    //添加事件监听    yesB.addActionListener(this);    cancelB.addActionListener(this);    this.setSize(400,300);    this.setTitle("删除学生信息");    this.setVisible(true);    this.setLocation(200,200);    //窗口关闭事件监听        this.addWindowListener(new WindowAdapter()    {      public void windowClosing( WindowEvent event)      {shutDown();}    }    );      }      //按钮的监听 public void actionPerformed(ActionEvent e){     if(e.getSource()==yesB){       del();     }     if(e.getSource()==cancelB){       shutDown();     }   }//////////////////////////////////////////////////////////////////////////////////////////////////   private void del() {   	    SNO=text1.getText();    try{      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");      String url="jdbc:odbc:STU";      Connection conn = DriverManager.getConnection(url,"sa","");      String COURSE = "DELETE FROM course WHERE Sno='"+ SNO +"'";      String STUDENT="DELETE FROM student WHERE Sno='"+ SNO +"'";                        Statement ps1=conn.createStatement();      ps1.executeUpdate(STUDENT);            Statement ps2=conn.createStatement();      ps2.executeUpdate(COURSE);      conn.close();                     //  JOptionPane.showMessageDialog(null,e.getMessage(),  //                     "数据库删除异常!",JOptionPane.ERROR_MESSAGE);            JOptionPane.showMessageDialog(this,"删除成功!");           }    catch(SQLException e){            JOptionPane.showMessageDialog(null,e.getMessage(),                       "数据库删除异常!",JOptionPane.ERROR_MESSAGE);       }    catch(Exception e){       e.printStackTrace();}/////////////////////////////////////////////////   }   private void shutDown(){     parent3.setVisible(true);     this.dispose();   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -