您好,登錄后才能下訂單哦!
這篇文章主要介紹了java怎么實(shí)現(xiàn)簡(jiǎn)易的學(xué)籍管理系統(tǒng),具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
具體內(nèi)容如下
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 = {"姓名", "語文", "數(shù)學(xué)", "外語", "總分"}; public JTable table; public static void main( String[] args ) { new TestStudentManager(); } TestStudentManager() { JFrame frame = new JFrame("模擬學(xué)生管理系統(tǒng)"); table = new JTable(unit, name); JPanel southPanel = new JPanel(); southPanel.add(new JLabel("添加學(xué)生數(shù)")); JButton calc = new JButton("計(jì)算成績(jī)"); JButton save = new JButton("保存學(xué)生信息"); JTextField input = new JTextField(5); southPanel.add(input); southPanel.add(calc); southPanel.add(save); frame.add(new JLabel("歡迎訪問學(xué)生管理系統(tǒng)"), 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("歡迎訪問學(xué)生管理系統(tǒng)"), 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("學(xué)生信息.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, "保存成功,存放至:學(xué)生信息.txt"); } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“java怎么實(shí)現(xiàn)簡(jiǎn)易的學(xué)籍管理系統(tǒng)”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。