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

📄 mainpanel.java

📁 学籍管理系统
💻 JAVA
字号:
/*
 * MainPanel.java
 *
 * Created on 2007年4月14日, 下午2:17
 */

package webmaneger;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  kk
 */
public class MainPanel extends javax.swing.JPanel {
    
    /** Creates new form MainPanel */
    public MainPanel() {
        initComponents();
        for(int i=0;i<student.length;i++)
        {
            student[i]=new Vector();
        }
        initInfo();
        initColumn();
        updataTable();
    }
    
    
    /** 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() {
        jScrollPane1 = new javax.swing.JScrollPane();
        studentTable = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        btnNew = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        studentTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"忘", null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "姓名", "学号", "性别", "年龄", "专业", "总评成绩"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        jScrollPane1.setViewportView(studentTable);

        jLabel1.setText("\u5b66\u751f\u6210\u7ee9\u7ba1\u7406");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "\u4e00\u5e74\u7ea7", "\u4e8c\u5e74\u7ea7" }));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });

        jButton1.setText("\u4ece\u4f4e\u5230\u9ad8");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jButton2.setText("\u4ece\u9ad8\u5230\u4f4e");
        jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton2MouseClicked(evt);
            }
        });

        jButton4.setText("\u5220\u9664");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton4MouseClicked(evt);
            }
        });

        btnNew.setText("\u65b0\u5efa");
        btnNew.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnNewMouseClicked(evt);
            }
        });

        jButton3.setText("\u7f16\u8f91");
        jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton3MouseClicked(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                        .add(jComboBox1, 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(btnNew, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 58, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jButton3)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel1)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(2, 2, 2)
                                .add(jButton4)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jButton1)
                                .add(6, 6, 6)
                                .add(jButton2)))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 26, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(btnNew)
                    .add(jButton3)
                    .add(jButton4)
                    .add(jButton1)
                    .add(jButton2))
                .add(19, 19, 19)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 265, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton3MouseClicked
        flag=1;
        currentID=(String) studentTable.getValueAt(studentTable.getSelectedRow(),1);
        Input input=new Input();
        input.setVisible(true);// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_jButton3MouseClicked

    private void btnNewMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnNewMouseClicked
        flag=0;
        Input input=new Input();
        input.setVisible(true);
     
// TODO 将在此处添加您的处理代码:
    }//GEN-LAST:event_btnNewMouseClicked

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
// TODO 将在此处添加您的处理代码:
        now=jComboBox1.getSelectedIndex();
        updataTable();  
    }//GEN-LAST:event_jComboBox1ItemStateChanged
    
    private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseClicked
// TODO 将在此处添加您的处理代码:
         StudentInfo temp=new StudentInfo();
        for(int i=0;i<student[now].size()-1;i++)
            for(int j=i;j<student[now].size();j++) 
            if(((StudentInfo)student[now].elementAt(i)).Score<((StudentInfo)student[now].elementAt(j)).Score) {
               temp=(StudentInfo)student[now].elementAt(i);
               student[now].set(i,student[now].elementAt(j));
               student[now].set(j,temp);
            }
       updataTable();  
        
    }
    /*
    private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
// TODO 将在此处添加您的处理代码:
        Input input=new Input();
        input.setVisible(true);
        
    }//GEN-LAST:event_jButton2MouseClicked
    */
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
// TODO 将在此处添加您的处理代码:
        StudentInfo temp=new StudentInfo();
        for(int i=0;i<student[now].size()-1;i++)
            for(int j=i;j<student[now].size();j++) 
            if(((StudentInfo)student[now].elementAt(i)).Score>((StudentInfo)student[now].elementAt(j)).Score) {
               temp=(StudentInfo)student[now].elementAt(i);
               student[now].set(i,student[now].elementAt(j));
               student[now].set(j,temp);
            }
       updataTable();     
    }//GEN-LAST:event_jButton1MouseClicked
        
    private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseClicked
     if(studentTable.getSelectedRow()!=-1)
     { String tempID=(String)studentTable.getValueAt(studentTable.getSelectedRow(),1);
        for(int i=0;i<student[now].size();i++) {
            if(tempID.compareTo(((StudentInfo)student[now].elementAt(i)).ID)==0) {
                student[now].remove(i);
            }
        }
        updataTable();}
    }//GEN-LAST:event_jButton4MouseClicked
    
    public void updataTable() {
        tableVector.removeAllElements();
        for(int i=0;i<student[now].size();i++) {
            tableVector.add(((StudentInfo)student[now].elementAt(i)).getDataVector());
        }
        DefaultTableModel tableModel=new DefaultTableModel();
        tableModel.setDataVector(tableVector,columnName);
        studentTable.setModel(tableModel);
        jScrollPane1.setViewportView(studentTable);
    }
    public void initColumn() {
        columnName.add("姓名");
        columnName.add("学号");
        columnName.add("性别");
        columnName.add("年龄");
        columnName.add("专业");
        columnName.add("总评成绩");
    }
    public void initInfo(){
        for(int i=0;i<10;i++) {
            StudentInfo studentInfo =new StudentInfo();
            studentInfo.Name="小王"+i;
            studentInfo.ID="050721"+i;
            studentInfo.Sex="男";
            studentInfo.Age="12"+i;
            studentInfo.Major="算";
            studentInfo.Score=i;
            student[0].add(studentInfo);
        }
                   for(int i=10;i<20;i++) {
            StudentInfo studentInfo =new StudentInfo();
            studentInfo.Name="小王"+i;
            studentInfo.ID="050721"+i;
            studentInfo.Sex="男";
            studentInfo.Age="12"+i;
            studentInfo.Major="算";
            studentInfo.Score=i;
            student[1].add(studentInfo);
        }
    }

    // 变量声明 - 不进行修改//GEN-BEGIN:variables
    private javax.swing.JButton btnNew;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable studentTable;
    // 变量声明结束//GEN-END:variables
    public static Vector student[]=new Vector[2];
   public static int now=0;
    public Vector columnName=new Vector();
    public Vector tableVector=new Vector();
    public static int flag=0;// 0代表新建 1代表编辑
 public static String currentID="";
}

⌨️ 快捷键说明

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