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

📄 setsubject.java

📁 java netbeans 学习程序合集
💻 JAVA
字号:
/*
 * SetSubject.java
 *
 * Created on 2007年9月3日, 上午10:17
 */

package org.Adam;

import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  Administrator
 */
public class SetSubject extends javax.swing.JFrame {
    ResultSet rs=null;
    /** Creates new form SetSubject */
    public SetSubject() {
        initComponents();
        this.setResizable(false);
        this.setLocationRelativeTo(this);
    }
    
    /** 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.
     */
    // <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">//GEN-BEGIN:initComponents
    private void initComponents() {
        jLabel1 = new javax.swing.JLabel();
        jTextFieldSubject = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButtonEnter = new javax.swing.JButton();
        jButtonCancle = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("\u57fa\u672c\u8bfe\u7a0b\u8bbe\u7f6e");
        jLabel1.setText("\u8bfe\u7a0b\u540d\u79f0\uff1a");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButtonEnter.setText("\u6dfb\u52a0");
        jButtonEnter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonEnterActionPerformed(evt);
            }
        });

        jButtonCancle.setText("\u53d6\u6d88");
        jButtonCancle.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonCancleActionPerformed(evt);
            }
        });

        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()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .addContainerGap()
                        .add(jScrollPane1, 0, 0, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(25, 25, 25)
                        .add(jLabel1)
                        .add(16, 16, 16)
                        .add(jTextFieldSubject, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
            .add(layout.createSequentialGroup()
                .add(39, 39, 39)
                .add(jButtonEnter)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 40, Short.MAX_VALUE)
                .add(jButtonCancle)
                .add(37, 37, 37))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(20, 20, 20)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jTextFieldSubject, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(20, 20, 20)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 227, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(21, 21, 21)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonEnter)
                    .add(jButtonCancle))
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonCancleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonCancleActionPerformed
// TODO 将在此处添加您的处理代码:
       this.dispose();
    }//GEN-LAST:event_jButtonCancleActionPerformed

    private void jButtonEnterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEnterActionPerformed
// TODO 将在此处添加您的处理代码:
       String Subject=this.jTextFieldSubject.getText();
       String sql="insert into 课程明细(科目) values('"+Subject+"')";
       DB dB=new DB();
      dB.Addstu(sql);
        Vector<Vector> data=new Vector();
        Vector<String> head=new Vector();
        String sql1="select distinct 科目 from 课程明细";
        DefaultTableModel tableModel=(DefaultTableModel)this.jTable1.getModel();
        
        head=dB.doClassTableHead(sql1);
        data=dB.doClassQuery(sql1);
        tableModel.setDataVector(data,head);
        this.jTable1.setModel(tableModel);       
        ((DefaultTableModel)jTable1.getModel()).fireTableStructureChanged();
        dB.closeAccessConnection();
    }//GEN-LAST:event_jButtonEnterActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SetSubject().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCancle;
    private javax.swing.JButton jButtonEnter;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldSubject;
    // 变量声明结束//GEN-END:variables
    
}

⌨️ 快捷键说明

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