2 Star 0 Fork 0

Ryeoyeong/数据库课程设计

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
StudentSelectPanel.java 2.61 KB
一键复制 编辑 原始数据 按行查看 历史
Ryeoyeong 提交于 2023-06-28 06:37 . 完善功能的学生端1.0
package sqltest;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public class StudentSelectPanel extends JPanel {
private JTable studentGradeTable=null;
Connector connector=null;
Redis redis=null;
PrintToFile printToFile =null;
String[][] studentGrade=null;
String sheetName;
String fileName;
HSSFWorkbook wb;
private JTableHeader title=null;
private JButton printButton=null;
public StudentSelectPanel(){
printButton=new JButton("打印成绩");
Redis redis=new Redis();
connector=new Connector();
String[] columnTitle={"课程号","成绩","等级"};
studentGrade= connector.getDBGrade(redis.getSno());
studentGradeTable=new JTable(studentGrade,columnTitle);
/*DefaultTableModel model = new DefaultTableModel(studentGrade, columnTitle) {
public boolean isCellEditable(int row, int column) {
return false;
}
};
studentGradeTable = new JTable(model);*/
title= studentGradeTable.getTableHeader();
new BorderLayout();
add(title,BorderLayout.NORTH );
add(studentGradeTable,BorderLayout.CENTER);
add(printButton,BorderLayout.SOUTH);
printButton.addActionListener(this::actionPerformed);
setVisible(true);
System.out.println(Arrays.deepToString(studentGrade));
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==printButton) {
redis = new Redis();
String[] title = {"课程名", "成绩", "等级"};
connector = new Connector();
studentGrade = connector.getDBGrade(redis.getSno());
sheetName = connector.getDBName(redis.getSno()) + "的成绩表";
wb=printToFile.getHSSFWorkbook("成绩表", title, studentGrade, null);
fileName = redis.getSno() + "-" + connector.getDBName(redis.getSno()) + ".xlsx";
try {
OutputStream os = new FileOutputStream("C:\\Users\\Lenovo\\Desktop\\" + fileName);
wb.write(os);
os.flush();
os.close();
} catch (Exception ex) {
ex.printStackTrace();
}
JOptionPane.showMessageDialog(this, "打印成功!", "提示", JOptionPane.PLAIN_MESSAGE);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/ryeoyeong/database-course-design.git
git@gitee.com:ryeoyeong/database-course-design.git
ryeoyeong
database-course-design
数据库课程设计
master

搜索帮助