📄 addscore.java
字号:
package 学生考试成绩分析程序;import java.awt.*;import javax.swing.*;import java.awt.event.*;import java.io.*;import java.util.*;public class AddScore extends JFrame implements ActionListener{ JLabel jlName=null,jlID=null,jlData=null,jlCount=null; JTextField jtData=null,jtCount=null; JButton jbCancel=null,jbok=null; static JTextField[] jtScore=new JTextField[40]; static int count=0; static String[] name=new String[40]; static String[] number=new String[40]; static String sClass=null,sCourse=null; String data; static String Count; static String Anumber,Aname; static String sscore; JTextField jtCheck=new JTextField(""); String check=jtCheck.getText(); public AddScore(){ JPanel jpLabel=new JPanel(); JPanel jpLAB=new JPanel(); JPanel jpButton=new JPanel(); JPanel jpTextField=new JPanel(); jpTextField.setLayout(new GridLayout(0,3)); jpLabel.setLayout(new GridLayout(0,4)); jpLAB.setLayout(new GridLayout(2,1)); jpTextField.add(new JLabel( " 学号 ")); jpTextField.add(new JLabel(" 姓名 ")); jpTextField.add(new JLabel(" 成绩 ")); for(int i=0;i<count;i++) { jpTextField.add(new JTextField(number[i])); jpTextField.add(new JTextField(name[i])); jpTextField.add(jtScore[i]=new JTextField("")); } jpLabel.add(new JLabel("考试日期")); jpLabel.add(jtData=new JTextField("")); jpLabel.add(new JLabel("考试人数")); jpLabel.add(jtCount=new JTextField("")); jpButton.add(jbok =new JButton("确定")); jpButton.add(jbCancel =new JButton("退出")); jpLAB.add(jpLabel); jpLAB.add(jpButton); getContentPane().setBackground(Color.WHITE); getContentPane().add(jpLAB,BorderLayout.SOUTH); getContentPane().add(jpTextField,BorderLayout.CENTER); jbok.addActionListener(this); jbCancel.addActionListener(this); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setTitle("综合性实验 "); this.pack(); this.setLocation(450,300); this.setVisible(true); } public AddScore(String Class,String course){ try { sClass=Class; sCourse=course; BufferedReader input=new BufferedReader(new FileReader("student.txt")); String line=input.readLine(); StringTokenizer tokenizer=new StringTokenizer(line,"*"); String s2=null; String[] student=new String[tokenizer.countTokens()]; for(int i=0;tokenizer.hasMoreTokens();i++) { student[i]=tokenizer.nextToken(); } for(int j=0,k=1;j<student.length;j++,k++) { if(k==3) { StringTokenizer scanner2=new StringTokenizer(sClass); s2=scanner2.nextToken(); if((student[j-2]+student[j-1]+student[j]).equals(s2)) { name[count]=student[j+2]; number[count]=student[j+3]; count++; } } if(k==6) { k=0; } } input.close(); new AddScore(); } catch(Exception ef) { JOptionPane.showMessageDialog(null, "增加失败"); } } public void actionPerformed(ActionEvent e) { if(e.getSource()==jbok) { data=jtData.getText(); Count=jtCount.getText(); try { BufferedWriter output=new BufferedWriter(new FileWriter("score.txt",true)); for(int m=0;m<count;m++) { sscore=jtScore[m].getText(); Anumber=number[m]; Aname=name[m]; if((!sClass.equals(check))&&(!sCourse.equals(check))&&(!Anumber.equals(check))&&(!Aname.equals(check))&&!sscore.equals(check)&&!data.equals(check)&&Count.equals(check)) { output.write(sClass+"*"+sCourse+"*"+Anumber+"*"+Aname+"*"+sscore+"*"+data+"*"+Count+"*"); if(m==count-1) { JOptionPane.showMessageDialog(null, "增加成功"); count=0; this.setVisible(false); } } else { JOptionPane.showMessageDialog(null, "输入错误,请重新输入"); break; } } output.close(); } catch(Exception k) { count=0; JOptionPane.showMessageDialog(null, "增加失败"); } } else if(e.getSource()==jbCancel) count=0; this.setVisible(false); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -