一、團隊名稱:
團隊成員
- 林藝薇 201721123032 網絡1712
- 黃毓穎 201721123033 網絡1712
- 唐川 201721123034 網絡1712
- 梁才玉 201721123038 網絡1712
任務分配
二、項目git地址
https://gitee.com/ev32/keshe/tree/master
三、項目git提交記錄截圖
四、項目功能架構圖與主要功能流程圖
思維導圖
成績管理流程圖
五、項目運行截圖
主界面
選擇用戶
教師登陸界面
教師增加學生信息
教師查看學生信息表
刪除學生信息
修改學生信息
查找學生成績
按班級查找
按姓名查找
按學號查找
各科成績柱狀圖
將成績導出到表格
學生登陸界面
學生功能
學生成績查詢功能
學生選課界面
六、項目關鍵代碼
1.數據庫代碼導入表格
public void LearningReport() throws SQLException {
ArrayList<String>list1=new ArrayList<String>();
Connection con = null; //建立數據庫連接
PreparedStatement ps = null;
ResultSet rs = null;
String sql ="select * from students "; //數據庫查詢表格所有記錄
con = JDBCUtil.getConnection();
ps = con.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
list1.add(0,rs.getString("stunum"));
list1.add(1,rs.getString("name"));
list1.add(2,rs.getString("classes"));
list1.add(3,rs.getString("gender"));
list1.add(4,rs.getString("javaScore"));
list1.add(5,rs.getString("mathScore"));
list1.add(6,rs.getString("englishScore"));
System.out.println();
}
HSSFWorkbook wb=new HSSFWorkbook();//創建Workbook對象(excel的文檔對象)
HSSFSheet sheet=wb.createSheet("表");//創建工作表
HSSFRow row1=sheet.createRow(0);
//設置單元格內容
HSSFCell cell=row1.createCell(0);
cell.setCellValue("學生成績表");
//合並單元格CellRangeAddress構造參數依次表示起始行,截至行,起始列, 截至列
sheet.addMergedRegion(new CellRangeAddress(0,0,0,6));
//在sheet里創建第二行,創建單元格並添加表頭內容
HSSFRow row2=sheet.createRow(1);
row2.createCell(0).setCellValue("學號");
row2.createCell(1).setCellValue("名字");
row2.createCell(2).setCellValue("班級");
row2.createCell(3).setCellValue("性別");
row2.createCell(4).setCellValue("JAVA成績");
row2.createCell(5).setCellValue("數學成績");
row2.createCell(6).setCellValue("英語成績");
//在sheet里從第三行開始創建表格中學生信息
int j=1;
for(int i=0;i<list1.size();i++) {
HSSFRow row=sheet.createRow(++j);
row.createCell(0).setCellValue(list1.get(i++));
row.createCell(1).setCellValue(list1.get(i++));
row.createCell(2).setCellValue(list1.get(i++));
row.createCell(3).setCellValue(list1.get(i++));
row.createCell(4).setCellValue(list1.get(i++));
row.createCell(5).setCellValue(list1.get(i++));
row.createCell(6).setCellValue(list1.get(i));
}
//導入Excel表
try {
FileOutputStream fout=new FileOutputStream("D:\\students.xlsx");//文件輸出流將數據寫入表格
wb.write(fout);//保存Excel文件
fout.close();//關閉文件流
}catch(Exception e){
e.printStackTrace();
}finally {
JDBCUtil.realeaseAll(rs, null, con);
}
}
@Override
//模糊查找
public List<Student> findStudentByStunum(String stunum) {
Connection con = null;
PreparedStatement pt = null;
ResultSet rs = null;
String sql="select * from students where stunum like '%"+stunum+"%'";
List<Student> list = new ArrayList<Student>();
try {
con = JDBCUtil.getConnection();
pt = con.prepareStatement(sql);
rs = pt.executeQuery();
while (rs.next()) {
// 封裝數據
Student stu = new Student();
stu.setId(rs.getInt("id"));
stu.setName(rs.getString("name"));
stu.setStunum(rs.getString("stunum"));
stu.setClasses(rs.getInt("classes"));
stu.setGender(rs.getString("gender"));
ArrayList<Course> scoreList=new ArrayList<Course>();
Course java=new Course("java",rs.getDouble("javaScore"));
Course math=new Course("math",rs.getDouble("mathScore"));
Course english=new Course("english",rs.getDouble("englishScore"));
scoreList.add(java);
scoreList.add(math);
scoreList.add(english);
stu.setScoreList(scoreList);
list.add(stu);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
JDBCUtil.realeaseAll(rs, pt, con);
}
return list;
}
2.柱狀圖的實現
public static JFreeChart createChart(CategoryDataset dataset)
{//創建一個JFreeChart
JFreeChart chart=ChartFactory.createBarChart("hi", "成績情況",
"人數", dataset, PlotOrientation.VERTICAL, true, true, false);
//設置主標題
chart.setTitle(new TextTitle("學生成績統計",new Font("宋體",Font.BOLD+Font.ITALIC,20)));
//獲得圖標中間部分,即plot
CategoryPlot plot=(CategoryPlot)chart.getPlot();
//獲得橫坐標
CategoryAxis categoryAxis=plot.getDomainAxis();
//設置橫坐標字體
categoryAxis.setLabelFont(new Font("微軟雅黑",Font.BOLD,12));
return chart;
}
public static JPanel createPanel(String course) throws SQLException
{
JFreeChart chart =createChart(createDataset(course));
//將chart對象放入Panel面板中去,ChartPanel類已繼承Jpanel
return new ChartPanel(chart);
}
七、項目代碼掃描結果及改正。
錯誤一:重寫類中的方法是沒加方法重寫標記
修改后
錯誤二:if語句缺少大括號
錯誤三:
八、尚待改進或者新的想法
- 注冊和登錄功能還不太完善。
- 沒有實現多線程。
- Gui界面不太美觀。
- jFreeChart柱狀圖關閉時會默認關閉所有窗口,柱狀圖功能還不夠完善。