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

📄 addstudent.java

📁 管理系统实现的源代码,
💻 JAVA
字号:
/* * addStudent.java * * Created on 2008年12月5日, 下午6:08 */package 学生成绩管理系统;import java.sql.ResultSet;import java.sql.SQLException;import javax.swing.JOptionPane;/** * * @author  Administrator */public class addStudent extends javax.swing.JDialog {    private ResultSet rs;    /** Creates new form addStudent */    public addStudent(java.awt.Frame parent, boolean modal) {        super(parent, modal);        initComponents();    }    addStudent() {        initComponents();    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    @SuppressWarnings("unchecked")    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents    private void initComponents() {        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        jLabel3 = new javax.swing.JLabel();        a1 = new javax.swing.JTextField();        a2 = new javax.swing.JTextField();        a3 = new javax.swing.JTextField();        jLabel4 = new javax.swing.JLabel();        a4 = new javax.swing.JTextField();        jLabel5 = new javax.swing.JLabel();        a5 = new javax.swing.JTextField();        jLabel6 = new javax.swing.JLabel();        a6 = new javax.swing.JTextField();        ok = new javax.swing.JButton();        cancell = new javax.swing.JButton();        jLabel7 = new javax.swing.JLabel();        a7 = new javax.swing.JTextField();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        setTitle("增加学生信息");        jLabel1.setText("班级");        jLabel2.setText("姓名");        jLabel3.setText("学号");        jLabel4.setText("语文");        jLabel5.setText("数学");        jLabel6.setText("英语");        ok.setText("确定");        ok.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                okActionPerformed(evt);            }        });        cancell.setText("取消");        cancell.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                cancellActionPerformed(evt);            }        });        jLabel7.setText("id");        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(layout.createSequentialGroup()                .addContainerGap(28, Short.MAX_VALUE)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)                            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()                                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)                                    .add(jLabel5)                                    .add(jLabel6)                                    .add(jLabel4)                                    .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel7))                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED))                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel2)                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel1)                            .add(org.jdesktop.layout.GroupLayout.TRAILING, jLabel3))                        .add(30, 30, 30)                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)                            .add(a7)                            .add(a6)                            .add(org.jdesktop.layout.GroupLayout.TRAILING, a2)                            .add(org.jdesktop.layout.GroupLayout.TRAILING, a3)                            .add(a1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)                            .add(a4)                            .add(a5))                        .add(241, 241, 241))                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()                        .add(ok)                        .add(56, 56, 56)                        .add(cancell)                        .add(165, 165, 165))))        );        layout.setVerticalGroup(            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)            .add(layout.createSequentialGroup()                .add(44, 44, 44)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(jLabel1)                    .add(a1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(a2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)                    .add(jLabel2))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(a3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)                    .add(jLabel3))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)                    .add(a4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)                    .add(jLabel4))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(jLabel5)                    .add(a5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(jLabel6)                    .add(a6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(jLabel7)                    .add(a7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)                    .add(cancell)                    .add(ok))                .add(47, 47, 47))        );        pack();    }// </editor-fold>//GEN-END:initComponents    void clearText() {        a1.setText("");        a2.setText("");        a3.setText("");        a4.setText("");        a5.setText("");        a6.setText("");        a7.setText("");    }//end clearTextprivate void cancellActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancellActionPerformed// TODO add your handling code here:     System.exit(0);}//GEN-LAST:event_cancellActionPerformedprivate void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed// TODO add your handling code here:    try {        DBM db = new DBM();        if (a1.getText().length() == 0 || a2.getText().length() == 0 || a3.getText().length() == 0 || a4.getText().length() == 0 || a5.getText().length() == 0) {            JOptionPane.showMessageDialog(null, "字段输入不能有空值", "警告",                    JOptionPane.WARNING_MESSAGE);        } else {            String sql0 = "insert into student(学号,班级,姓名,id) values('" + a3.getText() + "','" + a1.getText() + "','" + a2.getText() + "','" + Integer.parseInt(a7.getText()) + "')";            String sql1 = "insert into course(id,班级,语文,数学,英语) values("+Integer.parseInt(a7.getText()) + ",'" + a1.getText() + "'," + Integer.parseInt(a4.getText()) + "," + Integer.parseInt(a5.getText()) + "," + Integer.parseInt(a6.getText()) + ")";            db.executeSql(sql0);            db.executeSql(sql1);            JOptionPane.showMessageDialog(null, "增加学生信息成功!", "OK",                    JOptionPane.WARNING_MESSAGE);            clearText();            db.close();            System.exit(1);}//GEN-LAST:event_okActionPerformed        } catch (SQLException exc) {            exc.printStackTrace();            System.exit(1);        }    }    /**     * @param args the command line arguments     */    public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                addStudent dialog = new addStudent(new javax.swing.JFrame(), true);                dialog.addWindowListener(new java.awt.event.WindowAdapter() {                    public void windowClosing(java.awt.event.WindowEvent e) {                        System.exit(0);                    }                });                dialog.setVisible(true);            }        });    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JTextField a1;    private javax.swing.JTextField a2;    private javax.swing.JTextField a3;    private javax.swing.JTextField a4;    private javax.swing.JTextField a5;    private javax.swing.JTextField a6;    private javax.swing.JTextField a7;    private javax.swing.JButton cancell;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JLabel jLabel6;    private javax.swing.JLabel jLabel7;    private javax.swing.JButton ok;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

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