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

📄 jpanel5.java

📁 学生管理系统
💻 JAVA
字号:
package guanlixitong;

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import javax.swing.table.*;
import java.awt.Rectangle;
import java.awt.Font;

public class JPanel5
    extends JPanel implements ActionListener {
  public JPanel5() {
    try {
      jbInit();
    }
    catch (Exception ex) {
      ex.printStackTrace();
    }

  }

  public void actionPerformed(ActionEvent e) {



      if (jRadioButton1.isSelected()) {
        int n = sort("学号");
        initTabel(n);
      }
      else if (jRadioButton2.isSelected()) {
        int n = sort("姓名");
        initTabel(n);
      }
      else if (jRadioButton3.isSelected()) {
        int n = sort("成绩1");
        initTabel(n);
      }
      else if (jRadioButton4.isSelected()) {
        int n = sort("成绩2");
        initTabel(n);
      }
      else if (jRadioButton5.isSelected()) {
        int n = sort("成绩3");
        initTabel(n);
      }
      else if (jRadioButton6.isSelected()) {
        int n = sort("成绩4");
        initTabel(n);
      }
      else if (jRadioButton7.isSelected()) {
        int n = sort("成绩5");
        initTabel(n);
      }
      else if (jRadioButton8.isSelected()) {
        int n = sort();
        initTabel(n);
      }

    }


  private void jbInit() throws Exception {
    this.setLayout(null);
    jScrollPane1.setBounds(new Rectangle(109, 138, 565, 430));
    jPanel1.setBounds(new Rectangle(112, 103, 561, 38));
    jPanel1.setLayout(null);
    jRadioButton1.setBounds(new Rectangle(0, 12, 70, 23));
    jRadioButton2.setBounds(new Rectangle(70, 12, 70, 23));
    jRadioButton3.setBounds(new Rectangle(140, 12, 70, 23));
    jRadioButton4.setBounds(new Rectangle(218, 15, 70, 23));
    jRadioButton5.setBounds(new Rectangle(280, 12, 70, 23));
    jRadioButton6.setBounds(new Rectangle(350, 12, 70, 23));
    jRadioButton7.setBounds(new Rectangle(420, 12, 70, 23));
    jRadioButton8.setBounds(new Rectangle(490, 12, 70, 23));
    jRadioButton1.addActionListener(this);
    jRadioButton2.addActionListener(this);
    jRadioButton3.addActionListener(this);
    jRadioButton4.addActionListener(this);
    jRadioButton5.addActionListener(this);
    jRadioButton6.addActionListener(this);

    jRadioButton7.addActionListener(this);
    jRadioButton8.addActionListener(this);
    jLabel1.setText("jLabel1");
    jLabel1.setBounds(new Rectangle(110, 73, 345, 32));
    buttonGroup1.add(jRadioButton1);
    buttonGroup1.add(jRadioButton2);
    buttonGroup1.add(jRadioButton3);
    buttonGroup1.add(jRadioButton4);
    buttonGroup1.add(jRadioButton5);
    buttonGroup1.add(jRadioButton6);
    buttonGroup1.add(jRadioButton7);
    buttonGroup1.add(jRadioButton8);
    jPanel1.add(jRadioButton5);
    jPanel1.add(jRadioButton6);
    jPanel1.add(jRadioButton2);
    jPanel1.add(jRadioButton1);
    jPanel1.add(jRadioButton3);
    jPanel1.add(jRadioButton7);
    jPanel1.add(jRadioButton8);
    jPanel1.add(jRadioButton4);
    this.add(jLabel1);
    this.add(jScrollPane1);
    this.add(jPanel1);
    jScrollPane1.getViewport().add(jb);
    jb.setEnabled(false);
    int n=sort("学号");
    initTabel(n);
  }

  JTable jb = new JTable();
  DefaultTableModel jtm;
  JScrollPane jScrollPane1 = new JScrollPane();
  ButtonGroup buttonGroup1 = new ButtonGroup();
  JPanel jPanel1 = new JPanel();
  JRadioButton jRadioButton1 = new JRadioButton();
  JRadioButton jRadioButton2 = new JRadioButton();
  JRadioButton jRadioButton3 = new JRadioButton();
  JRadioButton jRadioButton4 = new JRadioButton();
  JRadioButton jRadioButton5 = new JRadioButton();
  JRadioButton jRadioButton6 = new JRadioButton();
  JRadioButton jRadioButton7 = new JRadioButton();
  JRadioButton jRadioButton8 = new JRadioButton();
  Student[] st = new Student[20];
  JLabel jLabel1 = new JLabel();
  public void initTabel(int k) {
    jtm = new DefaultTableModel();
    jtm.setRowCount(k);
    jtm.addColumn("学号");
    jtm.addColumn("姓名");
    jtm.addColumn("成绩1");
    jtm.addColumn("成绩2");
    jtm.addColumn("成绩3");
    jtm.addColumn("成绩4");
    jtm.addColumn("成绩5");
    jtm.addColumn("平均成绩");
    for (int i = 0; i < k; i++) {
      jtm.setValueAt(new Integer(st[i].学号), i, 0);
      jtm.setValueAt(st[i].姓名, i, 1);
      jtm.setValueAt(new Integer(st[i].成绩1), i, 2);
      jtm.setValueAt(new Integer(st[i].成绩2), i, 3);
      jtm.setValueAt(new Integer(st[i].成绩3), i, 4);
      jtm.setValueAt(new Integer(st[i].成绩4), i, 5);
      jtm.setValueAt(new Integer(st[i].成绩5), i, 6);
      jtm.setValueAt(new Double(st[i].平均成绩), i, 7);
    }
    jb.setModel(jtm);


  }

  public int sort() {
    int i = 0;
    String str = "jdbc:odbc:yangAcess";
    Connection con;

    String sSelect =
        "select 姓名,成绩1,成绩2,成绩3,成绩4,成绩5,学号,(成绩1+成绩2+成绩3+成绩4+成绩5)/5.0  from yang1 order by (成绩1+成绩2+成绩3+成绩4+成绩5)";

    ResultSet rs;

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection(str);
      Statement stmt = con.createStatement();
      rs = stmt.executeQuery(sSelect);

      while (rs.next()) {
        st[i] = new Student();
        st[i].姓名 = rs.getString("姓名");
        st[i].成绩1 = rs.getInt("成绩1");
        st[i].成绩2 = rs.getInt("成绩2");
        st[i].成绩3 = rs.getInt("成绩3");
        st[i].成绩4 = rs.getInt("成绩4");
        st[i].成绩5 = rs.getInt("成绩5");
        st[i].学号 = rs.getInt("学号");
        st[i].平均成绩 = rs.getDouble(8);
        i++;
      }

      con.close();
      stmt.close();
    }
    catch (Exception se) {System.out.print("fool");}
    return i;
  }

  public int sort(String num) {
    int i = 0;
    String str = "jdbc:odbc:yangAcess";
    Connection con;

    String sSelect =
        "select 姓名,成绩1,成绩2,成绩3,成绩4,成绩5,学号,(成绩1+成绩2+成绩3+成绩4+成绩5)/5.0 " +

       " from yang1"+" order by "+num;

    ResultSet rs;

    try {
      Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
      con = DriverManager.getConnection(str);
      Statement stmt = con.createStatement();
      rs = stmt.executeQuery(sSelect);

      while (rs.next()) {
        st[i] = new Student();
        st[i].姓名 = rs.getString("姓名");
        st[i].成绩1 = rs.getInt("成绩1");
        st[i].成绩2 = rs.getInt("成绩2");
        st[i].成绩3 = rs.getInt("成绩3");
        st[i].成绩4 = rs.getInt("成绩4");
        st[i].成绩5 = rs.getInt("成绩5");
        st[i].学号 = rs.getInt("学号");
        st[i].平均成绩 = rs.getDouble(8);
        i++;
      }

      con.close();
      stmt.close();
    }
    catch (Exception se) {System.out.print("fool");}
    return i;
  }

}

⌨️ 快捷键说明

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