代码拉取完成,页面将自动刷新
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);
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。