目录
编辑
需求分析:
登录界面(LoginPanel)
主界面(MainApp)
重写
1.班级重写(cs.practics.bean.BjBean.java)
2.课程重写(cs.practics.bean.CourseBean.java)
3.成绩重写(cs.practics.bean.MarkBean.java)
4.学生重写(cs.practics.bean.StudentBean.java)
班级管理
1.班级增加(cs.practics.bj.BJAddPanel)
2.班级查询(cs.practics.bj.BjFindPanel)
3.班级服务(cs.practics.service.BjService.java)
4.成绩添加(MarkInputPanel.java)
5.班级查询(MarkSelectPanel.java)
6.学生添加(StudentAddPanel.java)
7.学生查询(StudentSelectPanel.java)
课程管理
1.课程添加(cs.practics.course.CouresAddPanel.java)
2.课程查询(cs.practics.course.CouresSelectPanel.java)
服务
1.班级服务(cs.practics.service.BjService.java)
2.课程服务(cs.practics.service.CourseService.java)
3.成绩服务(cs.practics.service.MarkService.java)
4.学生服务(cs.practics.service.StudentService.java)
5.工具类(cs.practics.service.FileUtil.java)
本学生成绩管理系统模块是为了实现学校人力资源的优化和学生成绩管理的科学管理而设计的,通过试用本系统,可以更加有效的管理学生成绩信息,其中包括学生的基本信息,成绩信息并且具有信息的增加,查询,修改等功能。
本系统主要面向教师和学生。
(1)教师:登录管理、用户管理、成绩管理等。
(2)学生:主要使用的业务模块包括系统登录、查询成绩。
(1)专业编号遵循国家统计规范
(2)数据库的设计遵循本项目要求的统一设计规范。
本项目主要分为成绩管理、成绩查询设计管理、登录管理、学生管理。
角色名称 |
职责描述 |
教师 |
管理系统中的基础数据以及系统设置 |
学生 |
登陆系统之后,以及查看自己的成绩 |
功能类别 |
功能名称 |
描述 |
登录功能 |
学生登录 |
学生用户登录信息 |
教师登录 |
教师用户登录信息 |
|
班级管理 |
查询 |
查询班级信息 |
新增 |
新增班级信息 |
|
修改 |
修改班级信息 |
|
删除 |
删除班级信息 |
|
学生管理 |
查询 |
查询学生信息 |
新增 |
新增学生信息 |
|
修改 |
修改学生信息 |
|
删除 |
删除学生信息 |
|
成绩管理 |
成绩查询 |
查询学生的成绩信息 |
成绩录入 |
录入学生的成绩 |
|
成绩管理 |
修改学生的成绩 |
|
成绩查询统计 |
查询课程成绩及平均分 |
按班级分组查询课程及平均分 |
学生成绩查询 |
查询成绩 |
学生登录账户查询自己的每门成绩 |
正在上传…重新上传取消
需求名称 |
详细要求 |
整体风格 |
以蓝色为主色调 |
兼容性 |
能在主流浏览器(火狐、谷歌、IE8+、360浏览器)上运行 |
需求名称 |
详细要求 |
开发语言 |
Java或.NET |
运行环境 |
Jdk1.6+或.NET Framework 3.5以上 |
数据库 |
Mysql5.0或者SqlServer 2005以上 |
操作系统 |
Windows Server2008 |
主要质量属性 |
详细要求 |
正确性 |
无数据计算错误,无流程错误 |
健壮性 |
程序出错后,系统能正常捕获异常,不会导致程序终止运行 |
可靠性 |
系统支持7*24无间断运行,不会因系统功能的复杂运算而导致系统崩溃 |
性能、效率 |
数据请求在0.2S内返回 |
易用性 |
功能使用,操作简单,避免繁琐的逻辑设定 |
清晰性 |
功能结果及名称清晰,避免用户误解 |
安全性 |
用户必须成功登陆后,根据权限才可使用对应的功能 |
可扩展性 |
提供良好的系统接口,支持后续功能的开发扩展 |
兼容性 |
兼容主流浏览器(火狐、谷歌、IE8+、360浏览器) |
可移植性 |
能较好部署到其他版本的Windows操作系统上 |
无
package cs.practics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
@SuppressWarnings("serial")
public class LoginPanel extends JPanel {
private JTextField txtUserName;
private JTextField txtPwd;
private JButton btnOk;
private JButton btnQuit;
@SuppressWarnings("unused")
private MainApp parent;
public LoginPanel(MainApp parent){
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("用户名:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtUserName = new JTextField();
txtUserName.setBounds(570, 200, 200, 30);
add(txtUserName);
JLabel jLabel2 = new JLabel("密码:");
jLabel2.setBounds(500, 250, 70, 30);
add(jLabel2);
txtPwd = new JTextField();
txtPwd.setBounds(570, 250, 200, 30);
add(txtPwd);
btnOk= new JButton("确定");
btnOk.setBounds(580, 300, 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (txtUserName.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "用户名不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return ;
}
if (txtPwd.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "密码不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return ;
}
if (txtUserName.getText().equals("1") && txtPwd.getText().equals("1")){
JOptionPane.showMessageDialog(null, "登录成功!");
parent.loginSuccess();
}else{
JOptionPane.showMessageDialog(null, "失败成功!");
}
}
});
btnQuit = new JButton("退出");
btnQuit.setBounds(680, 300, 80, 30);
add(btnQuit);
btnQuit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
parent.quit();
}
});
}
}
package cs.practics;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import cs.practics.bj.BJAddPanel;
import cs.practics.bj.BjFindPanel;
import cs.practics.bj.MarkInputPanel;
import cs.practics.bj.MarkSelectPanel;
import cs.practics.bj.StudentAddPanel;
import cs.practics.bj.StudentSelectPanel;
import cs.practics.course.CourseAddPanel;
import cs.practics.course.CourseSelectPanel;
@SuppressWarnings("serial")
public class MainApp extends JFrame implements ActionListener {
@SuppressWarnings("unused")
private static final long seriaLVersionUID = -2550337629393921238L;
private JMenuBar menuBar;
private JMenu courseMenu;
private JMenu bjMenu;
private JMenu markMenu;
private JMenu studentMenu;
@SuppressWarnings("unused")
private JMenuItem[] courseMenuItems;
@SuppressWarnings("unused")
private JMenuItem[] bjMenuItems;
@SuppressWarnings("unused")
private JMenuItem[] markMenuItems;
@SuppressWarnings("unused")
private JMenuItem[] studentMenuItems;
private JPanel curPanel = null;
public MainApp() {
setTitle("学生成绩管理系统");
curPanel = new LoginPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
setSize(1600, 900);
setLocationRelativeTo(null);
setVisible(true);
initMenu();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initMenu() {
menuBar = new JMenuBar();
this.setJMenuBar(menuBar);
menuBar.setVisible(false);
bjMenu = new JMenu("班级管理");
String[] op = { "新增班级", "查询班级"};
initMenuItem(bjMenu, op);
menuBar.add(bjMenu);
courseMenu = new JMenu("课程管理");
op = new String[]{ "新增课程", "查询课程"};
initMenuItem(courseMenu, op);
menuBar.add(courseMenu);
studentMenu = new JMenu("学生管理");
op = new String[]{ "新增学生", "学生查询"};
initMenuItem(studentMenu, op);
menuBar.add(studentMenu);
markMenu = new JMenu("成绩管理");
op = new String[]{ "成绩查询", "录入成绩"};
initMenuItem(markMenu, op);
menuBar.add(markMenu);
}
private void initMenuItem(JMenu menu, String[] opers) {
JMenuItem[] menuItems = new JMenuItem[opers.length];
for (int i = 0; i < opers.length; i++) {
menuItems[i] = new JMenuItem(opers[i]);
menuItems[i].addActionListener(this);
menuItems[i].setActionCommand(menu.getActionCommand() + "-" + opers[i]);
menu.add(menuItems[i]);
}
}
@Override
public void actionPerformed(ActionEvent e) {
removePanel();
if ("课程管理-新增课程".equals(e.getActionCommand())){
curPanel = new CourseAddPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
} else if ("班级管理-新增班级".equals(e.getActionCommand())){
curPanel = new BJAddPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}else if ("班级管理-查询班级".equals(e.getActionCommand())){
curPanel = new BjFindPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}
/*else if ("班级管理-修改班级".equals(e.getActionCommand())){
curPanel = new BjDeletePanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}*/else if ("课程管理-查询课程".equals(e.getActionCommand())){
curPanel = new CourseSelectPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}else if ("学生管理-新增学生".equals(e.getActionCommand())){
curPanel = new StudentAddPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}else if ("学生管理-学生查询".equals(e.getActionCommand())){
curPanel = new StudentSelectPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}else if ("成绩管理-录入成绩".equals(e.getActionCommand())){
curPanel = new MarkInputPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}else if ("成绩管理-成绩查询".equals(e.getActionCommand())){
curPanel = new MarkSelectPanel(this);
getContentPane().add(curPanel, BorderLayout.CENTER);
refresh();
}
}
public void removePanel() {
if (curPanel != null) {
remove(curPanel);
}
curPanel = null;
}
public void refresh(){
getContentPane().validate();
getContentPane().repaint();
}
public void loginSuccess(){
menuBar.setVisible(true);
removePanel();
refresh();
}
public void quit(){
System.exit(0);
}
public static void main(String[] args) {
new MainApp();
}
}
package cs.practics.bean;
import java.io.Serializable;
@SuppressWarnings("serial")
public class BjBean implements Serializable {
private String BjID;
private String Bjname;
public String getBjID() {
return BjID;
}
public void setBjID(String bjID) {
BjID = bjID;
}
public String getBjname() {
return Bjname;
}
public void setBjname(String bjname) {
Bjname = bjname;
}
public String toString() {
return Bjname;
}
public String getBjName() {
// TODO Auto-generated method stub
return Bjname;
}
}
package cs.practics.bean;
import java.io.Serializable;
@SuppressWarnings("serial")
public class CourseBean implements Serializable{
private String courseID;
private String courseName;
public String getCourseID() {
return courseID;
}
public void setCourseID(String courseID) {
this.courseID = courseID;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String toString(){
return this.courseName;
}
}
package cs.practics.bean;
import java.io.Serializable;
import java.math.BigDecimal;
public class MarkBean implements Serializable{
private static final long serialVersionUID = -6391917037783889667L;
private String studentID;
private String studentName;
private String courseID;
private String courseName;
private String bjID;
private String bjName;
private BigDecimal mark;
public String getStuName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getBjID() {
return bjID;
}
public void setBjID(String bjID) {
this.bjID = bjID;
}
public String getBjName() {
return bjName;
}
public void setBjName(String bjName) {
this.bjName = bjName;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getCourseID() {
return courseID;
}
public void setCourseID(String courseID) {
this.courseID = courseID;
}
public BigDecimal getMark() {
return mark;
}
public void setMark(BigDecimal mark) {
this.mark = mark;
}
public Object getStudentName() {
// TODO Auto-generated method stub
return studentName;
}
}
package cs.practics.bean;
import java.io.Serializable;
import java.math.BigDecimal;
public class MarkBean implements Serializable{
private static final long serialVersionUID = -6391917037783889667L;
private String studentID;
private String studentName;
private String courseID;
private String courseName;
private String bjID;
private String bjName;
private BigDecimal mark;
public String getStuName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
public String getBjID() {
return bjID;
}
public void setBjID(String bjID) {
this.bjID = bjID;
}
public String getBjName() {
return bjName;
}
public void setBjName(String bjName) {
this.bjName = bjName;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public String getCourseID() {
return courseID;
}
public void setCourseID(String courseID) {
this.courseID = courseID;
}
public BigDecimal getMark() {
return mark;
}
public void setMark(BigDecimal mark) {
this.mark = mark;
}
public Object getStudentName() {
// TODO Auto-generated method stub
return studentName;
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.bean.BjBean;
import cs.practics.service.BjService;
@SuppressWarnings({ "serial", "unused" })
public class BJAddPanel extends JPanel {
private JTextField txtID;
private JTextField txtName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
public BJAddPanel (JFrame parent) {
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("班级ID:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtID = new JTextField();
txtID.setBounds(570, 200, 200, 30);
add(txtID);
JLabel jLabel2 = new JLabel("班级名称:");
jLabel2.setBounds(500, 250, 70, 30);
add(jLabel2);
txtName = new JTextField();
txtName.setBounds(570, 250, 200, 30);
add(txtName);
btnOk = new JButton("确定");
btnOk.setBounds(520, 300, 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (txtID.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "班级ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtName.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "班级名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
BjBean BjBean = new BjBean();
BjBean.setBjID(txtID.getText());
BjBean.setBjname(txtName.getText());
Integer rtn = BjService.bjService.add(BjBean);
if (rtn != 1) {
JOptionPane.showMessageDialog(null, txtID.getText() + "." + txtName.getText() + "添加失败,班级ID已经存在", "错误", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "添加成功!");
txtID.setText("");
txtName.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,300,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent.repaint();
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.bean.BjBean;
import cs.practics.service.BjService;
public class BjFindPanel extends JPanel {
private static final long serialVersionUID=3254423774866407987L;
private JTextField txtID;
private JTextField txtSelID;
private JTextField txtName;
//private JTextField txtBjName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
public BjFindPanel (JFrame parent) {
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("查询班级的ID:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtSelID = new JTextField();
txtSelID.setBounds(570, 200, 200, 30);
add(txtSelID);
JLabel jLabel1 = new JLabel("班级ID:");
jLabel1.setBounds(500, 250, 70, 30);
add(jLabel1);
txtID = new JTextField();
txtID.setBounds(570, 250, 200, 30);
add(txtID);
txtID.setEditable(false);
JLabel jLabel21 = new JLabel("班级名:");
jLabel21.setBounds(500, 300, 70, 30);
add(jLabel21);
txtName = new JTextField();
txtName.setBounds(570, 300, 200, 30);
add(txtName);
txtName.setEditable(false);
btnOk = new JButton("确定");
btnOk.setBounds(520, 350, 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@SuppressWarnings("unused")
@Override
public void actionPerformed(ActionEvent e) {
/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
if (txtSelID.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "班级ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
BjBean BjBean = new BjBean();
BjBean.setBjID(txtSelID.getText());
BjBean rtn = BjService.bjService.select(BjBean);
if (rtn == null) {
JOptionPane.showMessageDialog(null, "查询失败,班级ID不存在", "错误", JOptionPane.ERROR_MESSAGE);
txtSelID.setText("");
txtID.setText("");
txtName.setText("");
} else {
txtID.setText(rtn.getBjID());
txtName.setText(rtn.getBjName());
//txtBjName.setText(rtn.getBjName());
txtSelID.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,350,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent.repaint();
}
}
package cs.practics.service;
import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;
public class BjService {
public static final String dz1 = "E:/java实训/bj/data/data.data";
private List list = null;
public static BjService bjService = new BjService();
private BjService(){
try{
list = FileUtil.loadData(dz1);
}catch (ClassNotFoundException| IOException e){
e.printStackTrace();
}
if(list==null)list = new ArrayList<>();
}
public BjBean searchByBjID(String bjID){
for(BjBean bjBean:list){
if(bjBean.getBjID().equals(bjID)) return bjBean;
}
return null;
}
public int add(BjBean bean){
try {
BjBean tmp = searchByBjID(bean.getBjID());
if (tmp !=null) return -2;
list.add(bean);
FileUtil.writeData(list,dz1);
return 1;
}catch (Exception e){
e.printStackTrace();
return -1;
}
}
public List list() {
// TODO Auto-generated method stub
return list;
}
public Integer add(StudentBean studentBean) {
// TODO Auto-generated method stub
return add(studentBean);
}
public BjBean select(BjBean bjBean) {
// TODO Auto-generated method stub
BjBean rtn = searchByBjID(bjBean.getBjID());
if(rtn != null) {
return rtn;
}else {
return null;
}
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.service.BjService;
import cs.practics.service.CourseService;
import cs.practics.service.MarkService;
public class MarkInputPanel extends JPanel {
private static final long serialVersionUID = 3254423774866407987L;
protected static final String bjBean = null;
private JButton btnOK;
private JButton btnCancel;
private JButton btnSubmit;
private JFrame parent;
private JComboBox jComboBox;
private JComboBox jComboBox2;
private JTable jTable;
private JScrollPane jScrollPane=null;
public MarkInputPanel(JFrame parent) {
this.parent = parent;
setLayout(null);
// setLayout(new BorderLayout());
JLabel jbl2 = new JLabel("班级:");
jbl2.setBounds(180, 10, 70, 30);
add(jbl2);
List classes = BjService.bjService.list();
if (classes != null) {
BjBean[] arr = classes.toArray(new BjBean[0]);
jComboBox = new JComboBox<>(arr);
}else {
jComboBox = new JComboBox<>();
}
jComboBox.setBounds(250, 10, 200, 30);
add(jComboBox);
JLabel jbl3 = new JLabel("课程:");
jbl3.setBounds(480, 10, 70, 30);
add(jbl3);
List courses = CourseService.courseService.list();
if (courses != null) {
CourseBean[] arr = courses.toArray(new CourseBean[0]);
jComboBox2 = new JComboBox<>(arr);
}else {
jComboBox2 = new JComboBox<>();
}
jComboBox2.setBounds(550, 10, 200, 30);
add(jComboBox2);
btnOK = new JButton("查询");
btnOK.setBounds(780, 10, 80, 30);
add(btnOK);
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
BjBean bjBean = (BjBean) jComboBox.getSelectedItem();
CourseBean courseBean = (CourseBean) jComboBox2.getSelectedItem();
if (bjBean == null || courseBean == null) {
JOptionPane.showMessageDialog(null, "没有选班级或课程", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
List marks = MarkService.markService.search(bjBean.getBjID(), courseBean);
if (marks != null && marks.size() != 0) {
Object[] columnNames = { "学号", "姓名", "班级ID", "班级", "课程ID", "课程名", "成绩" };
Object[][] rowData = new Object[marks.size()][columnNames.length];
for (int i = 0; i < marks.size(); i++) {
MarkBean markBean = marks.get(i);
rowData[i] = new Object[] { markBean.getStudentID(),markBean.getStudentName(), markBean.getBjID(),
markBean.getBjName(), markBean.getCourseID(), markBean.getCourseName(), markBean.getMark() };
}
DefaultTableModel model = new DefaultTableModel(rowData, columnNames) {
private static final long serialVersionUID = -4509445279793353632L;
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 6)
return true;
return false;
}
public void setValueAt(Object value, int rowIndex, int columnIndex) {
if (columnIndex == 6) {
try {
new BigDecimal("" + value);
super.setValueAt(value, rowIndex, columnIndex);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "只能输入数字", "错误", JOptionPane.ERROR_MESSAGE);
}
}
}
};
jTable = new JTable(model);
jTable.setRowHeight(30);
jTable.setRowMargin(5);
jTable.setShowHorizontalLines(true);
jTable.setShowVerticalLines(true);
if (jScrollPane!=null){
remove(jScrollPane);
}
jScrollPane = new JScrollPane(jTable);
add(jScrollPane);
jScrollPane.setBounds(40, 60, 1200, 500);
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(870, 10, 80, 30);
add(btnCancel);
btnCancel.addActionListener(e -> cancel());
btnSubmit = new JButton("提交");
btnSubmit.setBounds(960, 10, 80, 30);
add(btnSubmit);
btnSubmit.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
List marks = new ArrayList<>();
for (int i = 0; i < jTable.getRowCount(); i++) {
MarkBean markBean = new MarkBean();
markBean.setStudentID(""+jTable.getValueAt(i, 0));
markBean.setStudentName(""+jTable.getValueAt(i, 1));
markBean.setBjID(""+jTable.getValueAt(i, 2));
markBean.setBjName(""+jTable.getValueAt(i, 3));
markBean.setCourseID(""+jTable.getValueAt(i, 4));
markBean.setCourseName(""+jTable.getValueAt(i, 5));
markBean.setMark(new BigDecimal(""+jTable.getValueAt(i,6)));
marks.add(markBean);
}
MarkService.markService.sumbit(marks);
JOptionPane.showMessageDialog(null, "提交成功!");
}
});
}
protected void cancel() {
parent.remove(this);
parent.validate();
parent. Repaint();
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.table.DefaultTableModel;
import cs.practics.bean.MarkBean;
import cs.practics.service.MarkService;
@SuppressWarnings("serial")
public class MarkSelectPanel extends JPanel {
private JTextField txtID;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
private JTable jTable;
private JScrollPane jScrollPane=null;
public MarkSelectPanel(JFrame parent){
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("学生ID:");
jLabel.setBounds(500,10,70,30);
add(jLabel);
txtID = new JTextField();
txtID.setBounds(550,10,200,30);
add(txtID);
btnOk = new JButton("查询" );
btnOk.setBounds(780,10,80,30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(txtID.getText().isEmpty()){
JOptionPane.showMessageDialog(null,"学生ID不能为空","错误",JOptionPane.ERROR_MESSAGE);
return;
}
List smb = MarkService.markService.searchByStuID(txtID.getText());
Object[] columnNames = {"学生名","课程ID", "课程名", "成绩" };
Object[][] rowData = new Object[smb.size()][columnNames.length];
if(smb.size()!=0){
for (int i=0;i cancel());
}
protected void cancel() {
parent.remove(this);
parent.validate();
parent.repaint();
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;
import cs.practics.service.BjService;
import cs.practics.service.StudentService;
public class StudentAddPanel extends JPanel {
private static final long serialVersionUID = 3254423774866407987L;
private JTextField txtID;
private JTextField txtName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
private JComboBox jComboBox;
public StudentAddPanel(JFrame parent) {
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("学生ID:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtID = new JTextField();
txtID.setBounds(570, 200, 200, 30);
add(txtID);
JLabel jLabel2 = new JLabel("学生姓名:");
jLabel2.setBounds(500, 250, 70, 30);
add(jLabel2);
txtName = new JTextField();
txtName.setBounds(570, 250, 200, 30);
add(txtName);
JLabel label1=new JLabel("学生班级:"); //创建标签
label1.setBounds(500,300,200,30);
add(label1);
List classes = BjService.bjService.list();
if(classes != null) {
BjBean[] arr = classes.toArray(new BjBean[0]);
jComboBox = new JComboBox<>(arr);
}else {
jComboBox = new JComboBox<>();
}
jComboBox.setBounds(570, 300, 200, 30);
add(jComboBox);
btnOk = new JButton("确定");
btnOk.setBounds(520,600 , 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//下拉框
BjBean bjBean = (BjBean)jComboBox.getSelectedItem();
System.out.println(bjBean.getBjID()+","+bjBean.getBjName());
if (txtID.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "学生ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
if (txtName.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "学生姓名不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
StudentBean studentBean = new StudentBean();
studentBean.setStudentID(txtID.getText());
studentBean.setStudentName(txtName.getText());
BjBean bjBean1=(BjBean)jComboBox.getSelectedItem();
Integer rtn = StudentService.studentService.add(studentBean,bjBean1);
if (rtn != 1) {
JOptionPane.showMessageDialog(null, txtID.getText() + "." + txtName.getText() + "添加失败,班级ID已经存在", "错误", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "添加成功!");
txtID.setText("");
txtName.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,600,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent. Repaint();
}
}
package cs.practics.bj;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.bean.CourseBean;
import cs.practics.bean.StudentBean;
import cs.practics.service.CourseService;
import cs.practics.service.StudentService;
public class StudentSelectPanel extends JPanel {
private static final long serialVersionUID = 3254423774866407987L;
private JTextField txtSelID;
private JTextField txtID;
private JTextField txtName;
private JTextField txtBjName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
public StudentSelectPanel(JFrame parent) {
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("查询的学生ID:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtSelID = new JTextField();
txtSelID.setBounds(570, 200, 200, 30);
add(txtSelID);
JLabel jLabel2 = new JLabel("学生ID:");
jLabel2.setBounds(500, 250, 70, 30);
add(jLabel2);
txtID = new JTextField();
txtID.setBounds(570, 250, 200, 30);
add(txtID);
txtID.setEditable(false);
JLabel jLabel21 = new JLabel("学生名:");
jLabel21.setBounds(500, 300, 70, 30);
add(jLabel21);
txtName = new JTextField();
txtName.setBounds(570, 300, 200, 30);
add(txtName);
txtName.setEditable(false);
JLabel jLabel211 = new JLabel("班级名:");
jLabel211.setBounds(500, 350, 70, 30);
add(jLabel211);
txtBjName = new JTextField();
txtBjName.setBounds(570, 350, 200, 30);
add(txtBjName);
txtBjName.setEditable(false);
btnOk = new JButton("确定");
btnOk.setBounds(520, 400, 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e) {
/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
if (txtSelID.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "学生ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
/*if (txtName.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "课程名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}*/
StudentBean studentBean = new StudentBean();
studentBean.setStudentID(txtSelID.getText());
//StudentBean.setStudentName(txtName.getText());
StudentBean rtn = StudentService.studentService.select(studentBean);
if (rtn ==null) {
JOptionPane.showMessageDialog(null,"查询失败,学生不存在", "错误", JOptionPane.ERROR_MESSAGE);
txtSelID.setText("");
txtID.setText("");
txtName.setText("");
txtBjName.setText("");
}
else {
txtBjName.setText(rtn.getBjname());
txtID.setText(rtn.getStudentID());
txtName.setText(rtn.getStudentname());
txtSelID.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,400,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent. Repaint();
}
}
package cs.practics.course;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.bean.CourseBean;
import cs.practics.service.CourseService;
@SuppressWarnings("serial")
public class CourseAddPanel extends JPanel {
private JTextField txtID;
private JTextField txtName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
public CourseAddPanel(JFrame parent){
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("课程ID:");
jLabel.setBounds(500,200,70,30);
add(jLabel);
txtID = new JTextField();
txtID.setBounds(570,200,200,30);
add(txtID);
JLabel jLabel2 = new JLabel("课程名:");
jLabel2.setBounds(500,250,70,30);
add(jLabel2);
txtName = new JTextField();
txtName.setBounds(570,250,200,30);
add(txtName);
btnOk = new JButton("确定");
btnOk.setBounds(520,300,80,30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(txtID.getText().isEmpty()){
JOptionPane.showMessageDialog(null,"课程ID不能为空","错误",JOptionPane.ERROR_MESSAGE);
return;
}
if(txtName.getText().isEmpty()){
JOptionPane.showMessageDialog(null,"课程名不能为空","错误",JOptionPane.ERROR_MESSAGE);
return;
}
CourseBean courseBean = new CourseBean();
courseBean.setCourseID(txtID.getText());
courseBean.setCourseName(txtName.getText());
Integer rtn = CourseService.courseService.add(courseBean);
if(rtn != 1){
JOptionPane.showMessageDialog(null,txtID.getText()+"."+txtName.getText()+"添加失败,课程ID已经存在","错误",JOptionPane.ERROR_MESSAGE);
}else {
JOptionPane.showMessageDialog(null,"添加成功!");
txtID.setText("");
txtName.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,300,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent. Repaint();
}
}
package cs.practics.course;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import cs.practics.MainApp;
import cs.practics.bean.CourseBean;
//import cs.practics.bean.StudentBean;
import cs.practics.service.CourseService;
public class CourseSelectPanel extends JPanel {
private static final long serialVersionUID = 3254423774866407987L;
private JTextField txtSelID;
private JTextField txtID;
private JTextField txtName;
//private JTextField txtCourseName;
private JButton btnOk;
private JButton btnCancel;
private JFrame parent;
public CourseSelectPanel(JFrame parent) {
this.parent = parent;
setLayout(null);
JLabel jLabel = new JLabel("查询的课程ID:");
jLabel.setBounds(500, 200, 70, 30);
add(jLabel);
txtSelID = new JTextField();
txtSelID.setBounds(570, 200, 200, 30);
add(txtSelID);
JLabel jLabel2 = new JLabel("课程ID:");
jLabel2.setBounds(500, 250, 70, 30);
add(jLabel2);
txtID = new JTextField();
txtID.setBounds(570, 250, 200, 30);
add(txtID);
txtID.setEditable(false);
JLabel jLabel21 = new JLabel("课程名:");
jLabel21.setBounds(500, 300, 70, 30);
add(jLabel21);
txtName = new JTextField();
txtName.setBounds(570, 300, 200, 30);
add(txtName);
txtName.setEditable(false);
btnOk = new JButton("确定");
btnOk.setBounds(520, 400, 80, 30);
add(btnOk);
btnOk.addActionListener(new ActionListener() {
@SuppressWarnings("null")
@Override
public void actionPerformed(ActionEvent e) {
/*BjBean bjBean = (BjBean )jComboBox.getSelectedItem();
System.out.println(bjBean.getBjID()+","+bjBean.getBjname());*/
if (txtSelID.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "课程ID不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}
/*if (txtName.getText().isEmpty()) {
JOptionPane.showMessageDialog(null, "课程名称不能为空", "错误", JOptionPane.ERROR_MESSAGE);
return;
}*/
CourseBean courseBean = new CourseBean();
courseBean.setCourseID(txtSelID.getText());
//StudentBean.setStudentName(txtName.getText());
CourseBean rtn = CourseService.courseService.select(courseBean);
if (rtn ==null) {
JOptionPane.showMessageDialog(null,"查询失败,课程不存在", "错误", JOptionPane.ERROR_MESSAGE);
txtSelID.setText("");
txtID.setText("");
txtName.setText("");
//txtCourseName.setText("");
}
else {
//txtCourseName.setText(rtn.getCourseName());
txtID.setText(rtn.getCourseID());
txtName.setText(rtn.getCourseName());
txtSelID.setText("");
}
}
});
btnCancel = new JButton("取消");
btnCancel.setBounds(680,400,80,30);
add(btnCancel);
btnCancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cancel();
}
});
}
protected void cancel(){
parent.remove(this);
parent.validate();
parent. Repaint();
}
}
package cs.practics.service;
import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cs.practics.bean.BjBean;
import cs.practics.bean.StudentBean;
public class BjService {
public static final String dz1 = "E:/java实训/bj/data/data.data";
private List list = null;
public static BjService bjService = new BjService();
private BjService(){
try{
list = FileUtil.loadData(dz1);
}catch (ClassNotFoundException| IOException e){
e.printStackTrace();
}
if(list==null)list = new ArrayList<>();
}
public BjBean searchByBjID(String bjID){
for(BjBean bjBean:list){
if(bjBean.getBjID().equals(bjID)) return bjBean;
}
return null;
}
public int add(BjBean bean){
try {
BjBean tmp = searchByBjID(bean.getBjID());
if (tmp !=null) return -2;
list.add(bean);
FileUtil.writeData(list,dz1);
return 1;
}catch (Exception e){
e.printStackTrace();
return -1;
}
}
public List list() {
// TODO Auto-generated method stub
return list;
}
public Integer add(StudentBean studentBean) {
// TODO Auto-generated method stub
return add(studentBean);
}
public BjBean select(BjBean bjBean) {
// TODO Auto-generated method stub
BjBean rtn = searchByBjID(bjBean.getBjID());
if(rtn != null) {
return rtn;
}else {
return null;
}
}
}
package cs.practics.service;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;
public class CourseService {
public static final String dz = "E:/java实训/course/data/data.data";
private List list = null;
public static CourseService courseService = new CourseService();
private CourseService(){
try{
list = FileUtil.loadData(dz);
}catch (ClassNotFoundException| IOException e){
e.printStackTrace();
}
if(list==null)list = new ArrayList<>();
}
public CourseBean searchByCourseID(String courseID){
for(CourseBean courseBean:list){
if(courseBean.getCourseID().equals(courseID)) return courseBean;
}
return null;
}
public int add(CourseBean bean){
try {
CourseBean tmp = searchByCourseID(bean.getCourseID());
if (tmp !=null) return -2;
list.add(bean);
FileUtil.writeData(list,dz);
return 1;
}catch (Exception e){
e.printStackTrace();
return -1;
}
}
public List list() {
// TODO Auto-generated method stub
return list;
}
public CourseBean select(CourseBean courseBean) {
// TODO Auto-generated method stub
CourseBean rtn = searchByCourseID(courseBean.getCourseID());
if(rtn != null) {
return rtn;
}
else {
return null;
}
}
}
package cs.practics.service;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.bean.StudentBean;
public class MarkService {
private List list = null;
public final String PATH = "E:/java实训/mark/data/data.data";
public static MarkService markService = new MarkService();
private MarkService() {
try {
list = FileUtil.loadData(PATH);
} catch (ClassNotFoundException | IOException e) {
e.printStackTrace();
}
if (list == null) list = new ArrayList<>();
}
/**
* 从mark库找出对应课程和班级的分数列表
* @param classID
* @param courseID
* @return
*/
public List searchByBjIDAndCourseID(String bjID, String courseID) {
List marks = new ArrayList<>();
for (MarkBean markBean: list) {
if (markBean.getBjID().equals(bjID) && markBean.getCourseID().equals(courseID)) {
marks.add(markBean);
}
}
return marks;
}
/**
* 从学生库找出该班级的学生,并且以List返回
* @param classID
* @return
*/
public List searchByBjIDAndCourseID(String bjID, CourseBean courseBean){
List marks = new ArrayList<>();
List students = StudentService.studentService.getByBjID(bjID);
if (students != null && students.size() > 0) {
for (StudentBean studentBean: students) {
MarkBean markBean = new MarkBean();
markBean.setBjID(studentBean.getBjID());
markBean.setBjName(studentBean.getBjname());
markBean.setCourseID(courseBean.getCourseID());
markBean.setCourseName(courseBean.getCourseName());
markBean.setStudentName(studentBean.getStudentname());
markBean.setStudentID(studentBean.getStudentID());
marks.add(markBean);
}
}
return marks;
}
public List searchByCourseAndClass(String courseID, String bjID){
List markList = new ArrayList<>();
for (MarkBean markBean : list) {
if (markBean.getBjID().equals(bjID) && markBean.getCourseID().equals(courseID)) {
markList.add(markBean);
}
}
return markList;
}
public List searchByStuID(String studentID){
List marks =new ArrayList<>();
for (MarkBean markBean:list){
if (markBean.getStudentID().equals(studentID)){
marks.add(markBean);
}
}
return marks;
}
public List search(String bjID, CourseBean courseBean){
List marks;
marks = searchByBjIDAndCourseID(bjID, courseBean.getCourseID());
if (marks == null || marks.size() == 0) {
marks = searchByBjIDAndCourseID(bjID, courseBean);
}
return marks;
}
public void sumbit(List marks){
for (MarkBean markBean:marks){
MarkBean tmp = null;
for (int i=0;i counter(String courseID, String bjID) {
List list = searchByCourseAndClass(courseID, bjID);
if (list == null || list.size() == 0) return null;
Map map = new HashMap<>();
BigDecimal max = null;
BigDecimal min = null;
BigDecimal sum = new BigDecimal(0);
for (MarkBean mark: list) {
if (mark.getMark() == null) continue;
if (max == null) {
max = mark.getMark();
min = mark.getMark();
}
if (mark.getMark().compareTo(max) > 0) {
max = mark.getMark();
}
if (mark.getMark().compareTo(min) < 0) {
min = mark.getMark();
}
sum = sum.add(mark.getMark());
}
sum = sum.divide(new BigDecimal(list.size()),1,BigDecimal.ROUND_DOWN);
map.put("最高分", max.toString());
map.put("最低分", min.toString());
map.put("平均分", sum.toString());
return map;
}
public List list(){
return list;
}
}
package cs.practics.service;
import java.util.ArrayList;
import java.util.List;
import cs.practics.bean.BjBean;
import cs.practics.bean.CourseBean;
import cs.practics.bean.MarkBean;
import cs.practics.bean.StudentBean;
import cs.practics.bj.MarkInputPanel;
@SuppressWarnings("unused")
public class StudentService {
private List list = null;
public static StudentService studentService = new StudentService();
private StudentService() {
try {
list = FileUtil.loadData("E:/java实训/student/data/data.data");
} catch (Exception e) {
e.printStackTrace();
}
// TODO Auto-generated constructor stub
if(list == null) list = new ArrayList<>();
}
public StudentBean searchByStudentID(String studentID) {
for(StudentBean studentBean: list) {
if (studentBean.getStudentID().equals(studentID)) return studentBean;
}
return null;
}
public int add(StudentBean studentBean,BjBean bjBean) {
try {
StudentBean tmp = searchByStudentID(studentBean.getStudentID());
if(tmp!=null) return -2;
studentBean.setBjID(bjBean.getBjID());
studentBean.setBjName(bjBean.getBjName());
list.add(studentBean );
FileUtil.writeData(list,"E:/java实训/student/data/data.data");
return 1;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
public List searchByBjID(String bjID, CourseBean courseBean) {
// TODO Auto-generated method stub
return searchByBjID(bjID, courseBean);
}
public List getByBjID1(String classID) {
// TODO Auto-generated method stub
return list;
}
public List getByBjID(String bjID) {
// TODO Auto-generated method stub
return list;
}
public StudentBean select(StudentBean studentBean) {
// TODO Auto-generated method stub
StudentBean rtn = searchByStudentID(studentBean.getStudentID());
if(rtn != null) {
return rtn;
}else {
return null;
}
}
}
提供IO包进行流数据处理
package cs.practics.service;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
@SuppressWarnings("serial")
public class FileUtil implements Serializable{
@SuppressWarnings("unchecked")
public static T loadData(String path) throws IOException,ClassNotFoundException{
File f = new File(path);
FileInputStream fis = new FileInputStream(f);
ObjectInputStream ois = new ObjectInputStream(fis);
T t = (T)(ois.readObject());
ois.close();
return t;
}
public static void writeData(Object obj,String path) throws IOException{
File f = new File(path);
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(obj);
oos.flush();
oos.close();
}
}
该程序的书写目前没有写完,还是很基础的一个系统,后续会跟进更新代码