📄 classtable.java
字号:
package caoyu;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
class ClassTable extends JFrame implements ActionListener{
public JRadioButton name = null;
public JRadioButton depatmentName= new JRadioButton("系名");
public JRadioButton classno = new JRadioButton("班级号码");
public JButton Mark_list = new JButton("班级成绩单");
public JTextField jt = null;
public JButton btn = null;
public JTable table = null;
public ClassTable()
{
this.initFrame();
this.setTitle("班级信息系统");
setSize(700,500);
setVisible(true);
}
public void initFrame()
{
Container container = this.getContentPane();
String[][] p = new String[100][7];
String[] n = {"classno ","departmentno ","gross_number ","enter_date ","monitor ","major "};
table = new JTable(p,n);
JLayeredPane jlp=new JLayeredPane();
jlp.setLayout(new GridLayout(1,7));//生成布局
JScrollPane s = new JScrollPane(table);
container.add(s, BorderLayout.CENTER);
name = new JRadioButton( "班长姓名" );
classno = new JRadioButton( "班级号");
btn = new JButton( "查询" );
jlp.add( name );
jlp.add( depatmentName);
jlp.add( classno);
jlp.add( Mark_list);
ButtonGroup buttongroup=new ButtonGroup();
buttongroup.add(name);
buttongroup.add(depatmentName);
buttongroup.add(classno);
jlp.add( btn );
jt = new JTextField( 10 );
jlp.add( jt );
container.add(jlp, BorderLayout.NORTH);
btn.addActionListener(this);
Mark_list.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn&&name.isSelected())//班长姓名查找信息
{try {
DBOperatorStudent op = new DBOperatorStudent();
ResultSet rs= op.queryStudent5(jt.getText().trim());
for(int i=0;rs.next();i++)
{
table.setValueAt(rs.getString(1),i,0);
table.setValueAt(rs.getString(2),i,1);
table.setValueAt(rs.getString(3),i,2);
table.setValueAt(rs.getString(4),i,3);
table.setValueAt(rs.getString(5),i,4);
table.setValueAt(rs.getString(6),i,5);
}
rs.close();
op.conn.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
}//if
else if(e.getSource()==btn&&classno.isSelected())//班级号码查找信息
{try {
DBOperatorStudent op = new DBOperatorStudent();
ResultSet rs= op.queryStudent6(jt.getText().trim());
for(int i=0;rs.next();i++)
{
table.setValueAt(rs.getString(1),i,0);
table.setValueAt(rs.getString(2),i,1);
table.setValueAt(rs.getString(3),i,2);
table.setValueAt(rs.getString(4),i,3);
table.setValueAt(rs.getString(5),i,4);
table.setValueAt(rs.getString(6),i,5);
}
rs.close();
op.conn.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
}//if
else if(e.getSource()==btn&&depatmentName.isSelected())//系名查找信息
{try {
DBOperatorStudent op = new DBOperatorStudent();
ResultSet rs= op.queryStudent7(jt.getText().trim());
for(int i=0;rs.next();i++)
{
table.setValueAt(rs.getString(1),i,0);
table.setValueAt(rs.getString(2),i,1);
table.setValueAt(rs.getString(3),i,2);
table.setValueAt(rs.getString(4),i,3);
table.setValueAt(rs.getString(5),i,4);
table.setValueAt(rs.getString(6),i,5);
}
rs.close();
op.conn.close();
}
catch(Exception ex) {
ex.printStackTrace();
}
}//if
else if(e.getSource()==Mark_list) //班级成绩查询
{ Total_Mark_list a=new Total_Mark_list(); }
else JOptionPane.showMessageDialog(this,"请选择一种查询方式");
}
public static void main(String args[])
{
ClassTable a=new ClassTable();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -