?? jpanel5.java~11~
字號:
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()) {
jButton1.setEnabled(true);
}
else if (jRadioButton2.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton3.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton4.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton5.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton6.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton7.isSelected()) {
jButton1.setEnabled(true);
}
else if (jRadioButton8.isSelected()) {
jButton1.setEnabled(true);
}
if (e.getSource() == jButton1) {
if (jRadioButton1.isSelected()) {
int n = sort("學號");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("姓名");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("成績1");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("成績2");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("成績3");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("成績4");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort("成績5");
initTabel(n);
}
else if (jRadioButton1.isSelected()) {
int n = sort();
initTabel(n);
}
}
}
private void jbInit() throws Exception {
this.setLayout(null);
jScrollPane1.setBounds(new Rectangle(70, 135, 591, 430));
jPanel1.setBounds(new Rectangle(70, 93, 591, 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(210, 12, 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);
jButton1.setBounds(new Rectangle(242, 56, 151, 36));
jButton1.setEnabled(false);
jButton1.setFont(new java.awt.Font("宋體", Font.PLAIN, 16));
jButton1.setForeground(Color.magenta);
jButton1.setText("排 序 ");
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(jRadioButton4);
jPanel1.add(jRadioButton3);
jPanel1.add(jRadioButton7);
jPanel1.add(jRadioButton8);
this.add(jScrollPane1);
this.add(jPanel1);
this.add(jButton1);
jScrollPane1.getViewport().add(jb);
jButton1.addActionListener(this);
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();
JButton jButton1 = new JButton();
Student[] st = new Student[20];
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, 1);
jtm.setValueAt(st[i].姓名, i, 1);
jtm.setValueAt(new Integer(st[i].成績1), i, 1);
jtm.setValueAt(new Integer(st[i].成績2), i, 1);
jtm.setValueAt(new Integer(st[i].成績3), i, 1);
jtm.setValueAt(new Integer(st[i].成績4), i, 1);
jtm.setValueAt(new Integer(st[i].成績5), i, 1);
jtm.setValueAt(new Double(st[i].平均成績), i, 1);
}
jb.setModel(jtm);
jb.setEnabled(false);
}
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" +
" order by"
+ " (成績1+成績2+成績3+成績4+成績5)/5.0 from yang1";
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 " +
" order by"
+ num + " from yang1";
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 + -