java实现简易的学籍管理系统

网友投稿 382 2022-08-25


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();

}

CoposU

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 = nhttp://ew File("学生信息.txt");

http:// 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");

}

}

二、运行


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:7 函数(python)
下一篇:3、运算符和表达式​
相关文章

 发表评论

暂时没有评论,来抢沙发吧~