这篇文章主要为大家详细介绍了java实现简易的学籍管理系统,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了java实现简易的学籍管理系统的具体代码,供大家参考,具体内容如下
一、 代码
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class TestStudentManager {
private int rows = 0;
private String[][] unit = new String[rows][5];
private String[] name = {"姓名", "语文", "数学", "外语", "总分"};
public JTable table;
public static void main( String[] args ) {
new TestStudentManager();
}
TestStudentManager() {
JFrame frame = new JFrame("模拟学生管理系统");
table = new JTable(unit, name);
JPanel southPanel = new JPanel();
southPanel.add(new JLabel("添加学生数"));
JButton calc = new JButton("计算成绩");
JButton save = new JButton("保存学生信息");
JTextField input = new JTextField(5);
southPanel.add(input);
southPanel.add(calc);
southPanel.add(save);
frame.add(new JLabel("欢迎访问学生管理系统"), BorderLayout.NORTH);
frame.add(southPanel, BorderLayout.SOUTH);
frame.add(new JScrollPane(table), BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
input.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
rows = Integer.valueOf(input.getText());
unit = new String[rows][5];
table = new JTable(unit, name);
System.out.println("xx");
frame.getContentPane().removeAll();
frame.add(new JScrollPane(table), BorderLayout.CENTER);
frame.add(southPanel, BorderLayout.SOUTH);
frame.add(new JLabel("欢迎访问学生管理系统"), BorderLayout.NORTH);
frame.validate();
table.setRowHeight(25);
}
});
calc.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
for (int i = 0; i < rows; i++) {
double sum = 0;
boolean flag = true;
for (int j = 1; j <= 3; j++) {
try {
sum += Double.valueOf(unit[i][j].toString());
} catch (Exception ee) {
flag = false;
table.repaint();
}
if (flag) {
unit[i][4] = "" + sum;
table.repaint();
}
}
}
}
});
save.addActionListener(new ActionListener() {
public void actionPerformed( ActionEvent e ) {
try {
write();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
}
void write() throws IOException {
File f = new File("学生信息.txt");
FileWriter fw = new FileWriter(f);
for (int i = 0; i < 5; i++) {
fw.write(name[i] + "\t");
}
fw.write("\r\n");
for (int i = 0; i < rows; i++) {
for (int j = 0; j < 5; j++) {
fw.write(unit[i][j] + "\t");
}
fw.write("\r\n");
}
fw.close();
JOptionPane.showMessageDialog(null, "保存成功,存放至:学生信息.txt");
}
}
二、运行
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:java实现简易的学籍管理系统


猜你喜欢
- ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
- 深入了解Spring的事务传播机制 2023-06-02
- Spring Security权限想要细化到按钮实现示例 2023-03-07
- Java实现顺序表的操作详解 2023-05-19
- JSP页面间传值问题实例简析 2023-08-03
- 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
- Java中的日期时间处理及格式化处理 2023-04-18
- SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
- Springboot整合minio实现文件服务的教程详解 2022-12-03
- JSP 制作验证码的实例详解 2023-07-30