scstfrom.java~7~

来自「这个是学生考试系统,里面有完整的代码加数据库SQL server」· JAVA~7~ 代码 · 共 109 行

JAVA~7~
109
字号
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 scstFrom extends JFrame {
    private ImageIcon im1 = new ImageIcon("img\\red_forum.gif");
    public scstFrom() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.setResizable(false);
        setTitle("删除试题");
        jLabel2.setFont(new java.awt.Font("隶书", Font.BOLD, 20));
        getContentPane().setLayout(null);
        jt1.setBounds(new Rectangle(100, 78, 172, 34));
        jLabel2.setForeground(SystemColor.desktop);
        jLabel2.setHorizontalAlignment(SwingConstants.CENTER);
        jLabel2.setText("试  题  删  除");
        jLabel2.setBounds(new Rectangle(87, 18, 191, 33));
        jLabel1.setForeground(Color.red);
        jButton1.addActionListener(new scstFrom_jButton1_actionAdapter(this));
        jButton1.setIcon(im1);
        this.getContentPane().add(jLabel2);
        jButton1.setBounds(new Rectangle(131, 189, 99, 35));
        jButton1.setText("删除");
        this.getContentPane().add(jt1);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(jButton1);
        jLabel1.setText("请输入要删除的试题编号,一但删除不可恢复请重新添加!");
        jLabel1.setBounds(new Rectangle(39, 139, 319, 26));
    }

    public static void main(String[] args) {
        scstFrom scstfrom = new scstFrom();
    }

    JTextField jt1 = new JTextField();
    JLabel jLabel1 = new JLabel();
    JLabel jLabel2 = new JLabel();
    JButton jButton1 = new JButton();
    public void jButton1_actionPerformed(ActionEvent e) {
         String num=jt1.getText().trim();
         Connection con=null;
         Statement s1=null;
         ResultSet rs=null;
         try
         {
             if(num.length()!=0)
             {
                 try
                {
                    Integer num1=Integer.parseInt(num);
                }
                catch(Exception ce)
                {
                    JOptionPane.showMessageDialog(null,"编号必须是数字!","提示",JOptionPane.ERROR_MESSAGE);
                }
                con=DBcon.link();
                s1=con.createStatement();
                rs=s1.executeQuery("select * from Question where Num='"+num+"'");
                if(rs.next())
                {
                    s1.executeUpdate("delete from Question where Num="+num+"");
                    JOptionPane.showMessageDialog(null,""+num+"号试题删除成功!");
                    jt1.setText("");
                    jt1.requestFocus();
                }
                else
                {
                    JOptionPane.showMessageDialog(null,"对不起,您要删除的试题编号不存在!");
                    jt1.setText("");
                    jt1.requestFocus();
                }
             }
             else
             {
                 JOptionPane.showMessageDialog(null,"删除失败");
             }

         }
         catch(SQLException co)
         {
             co.getMessage();
         }
    }
}


class scstFrom_jButton1_actionAdapter implements ActionListener {
    private scstFrom adaptee;
    scstFrom_jButton1_actionAdapter(scstFrom adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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