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

📄 selectmasks.java

📁 java netbeans 学习程序合集
💻 JAVA
字号:
/*
 * SelectMasks.java
 *
 * Created on 2007年9月5日, 下午2:25
 */

package org.Adam;

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

/**
 *
 * @author  Administrator
 */
public class SelectMasks extends javax.swing.JFrame {
    ResultSet rs=null;
     public String a=new String();
    /** Creates new form SelectMasks */
    public SelectMasks() {
        initComponents();
        this.setLocationRelativeTo(this);
        this.setResizable(false);
        this.jComboBox1.addItem("");
        GetSubject();
        this.jComboBox2.addItem("");
        GetGrade();
    }
        private void GetGrade(){
        String sql="select distinct 年级 from 班级信息 ";
        DB dB=new DB();
        rs=dB.SelectpassDb(sql);
        try {
           while(rs.next()){
            a=rs.getString("年级");
            this.jComboBox2.addItem(a);
           }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    private void GetSubject(){
        String sql="select distinct 科目 from 课程明细";
        DB dB=new DB();
        rs=dB.SelectpassDb(sql);
        try {
           while(rs.next()){
            a=rs.getString("科目");
            this.jComboBox1.addItem(a);
           }
            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    /** 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() {
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jComboBoxClass = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldID = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jLabel5 = new javax.swing.JLabel();
        jComboBoxXueqi = new javax.swing.JComboBox();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jButtonSelect = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("\u6210\u7ee9\u67e5\u8be2");
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("\u6210\u7ee9\u67e5\u8be2"));
        jLabel1.setText("\u5e74\u7ea7\uff1a");

        jLabel2.setText("\u73ed\u7ea7\uff1a");

        jComboBoxClass.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "\u7535\u4fe1", "\u5e94\u7535", "\u7269\u65591\u73ed", "\u7269\u65592\u73ed", "\u7269\u65593\u73ed" }));

        jLabel3.setText("\u6309\u79d1\u76ee\u67e5\u8be2\uff1a");

        jLabel4.setText("\u6309\u5b66\u53f7\u67e5\u8be2\uff1a");

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

            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jLabel5.setText("\u8bf7\u9009\u62e9\u5b66\u671f\uff1a");

        jComboBoxXueqi.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "", "\u7b2c\u4e00\u5b66\u671f", "\u7b2c\u4e8c\u5b66\u671f", "\u7b2c\u4e09\u5b66\u671f", "\u7b2c\u56db\u5b66\u671f", "\u7b2c\u4e94\u5b66\u671f", "\u7b2c\u516d\u5b66\u671f", "\u7b2c\u4e03\u5b66\u671f", "\u7b2c\u516b\u5b66\u671f" }));

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jLabel1)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 102, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(19, 19, 19)
                        .add(jLabel2)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jComboBoxClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 101, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel4))
                        .add(19, 19, 19)
                        .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jComboBox1, 0, 211, Short.MAX_VALUE)
                            .add(jTextFieldID, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 211, Short.MAX_VALUE)
                            .add(jComboBoxXueqi, 0, 211, Short.MAX_VALUE))))
                .addContainerGap(40, Short.MAX_VALUE))
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel5)
                .addContainerGap(270, Short.MAX_VALUE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel1)
                    .add(jLabel2)
                    .add(jComboBoxClass, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jComboBox2, 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(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel3)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel4)
                    .add(jTextFieldID, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(21, 21, 21)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel5)
                    .add(jComboBoxXueqi, 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.DEFAULT_SIZE, 274, Short.MAX_VALUE))
        );

        jButtonSelect.setText("\u67e5\u8be2\u6210\u7ee9\u4fe1\u606f");
        jButtonSelect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSelectActionPerformed(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(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(layout.createSequentialGroup()
                        .add(139, 139, 139)
                        .add(jButtonSelect)))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonSelect)
                .addContainerGap())
        );
        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonSelectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSelectActionPerformed
// TODO 将在此处添加您的处理代码:
        String Grade=this.jComboBox2.getSelectedItem().toString();
        String Class=this.jComboBoxClass.getSelectedItem().toString();
        String Subject=this.jComboBox1.getSelectedItem().toString();
        String ID=this.jTextFieldID.getText();
        String Xueqi=this.jComboBoxXueqi.getSelectedItem().toString();
        Vector<Vector> data=new Vector();
        Vector<String> head=new Vector();
        String sql="select distinct a.姓名,c.科目,b.成绩 from 学生档案 a,课程及成绩 b,课程明细 c,学期 d where a.m_id=b.s_id and b.subject_ID=c.subject_ID and b.xueqi_ID=d.xueqi_ID and  a.年级='"+Grade+"' and a.班级='"+Class+"' ";
        
        if(!Subject.equals("") && ID.equals("") && Xueqi.equals("")){
            sql=sql+" and c.科目='"+Subject+"' ";
        } 
        if(Subject.equals("") && !ID.equals("") && Xueqi.equals("")){
            sql=sql+" and a.学号='"+ID+"' ";
        } 
        if(Subject.equals("") && ID.equals("") && !Xueqi.equals("")){
            sql=sql+" and d.学期='"+Xueqi+"' ";
        } 
        if(!Subject.equals("") && !ID.equals("") && Xueqi.equals("")){
            sql=sql+" and c.科目='"+Subject+"' and a.学号='"+ID+"' ";
        } 
        if(!Subject.equals("") && ID.equals("") && !Xueqi.equals("")){
            sql=sql+" and c.科目='"+Subject+"' and d.学期='"+Xueqi+"' ";
        } 
        if(Subject.equals("") && !ID.equals("") && !Xueqi.equals("")){
            sql=sql+" and d.学期='"+Xueqi+"' and a.学号='"+ID+"' ";
        } 
        if(!Subject.equals("") && !ID.equals("") && !Xueqi.equals("")){
            sql=sql+" and c.科目='"+Subject+"' and a.学号='"+ID+"' and d.学期='"+Xueqi+"' ";
        } 
        DefaultTableModel tableModel=(DefaultTableModel)this.jTable1.getModel();
        DB dB=new DB();      
        head=dB.doClassTableHead(sql);
        data=dB.doClassQuery(sql);
        tableModel.setDataVector(data,head);
        this.jTable1.setModel(tableModel);       
        ((DefaultTableModel)jTable1.getModel()).fireTableStructureChanged();
        dB.closeAccessConnection();
    }//GEN-LAST:event_jButtonSelectActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new SelectMasks().setVisible(true);
            }
        });
    }
    
    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton jButtonSelect;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBoxClass;
    private javax.swing.JComboBox jComboBoxXueqi;
    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.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextFieldID;
    // 变量声明结束//GEN-END:variables
    
}

⌨️ 快捷键说明

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