diff --git a/out/production/fuckJavaGui/autoScore/mainGUI.class b/out/production/fuckJavaGui/autoScore/mainGUI.class new file mode 100644 index 0000000..08e2a9b Binary files /dev/null and b/out/production/fuckJavaGui/autoScore/mainGUI.class differ diff --git a/out/production/fuckJavaGui/autoScore/score.class b/out/production/fuckJavaGui/autoScore/score.class index bd3d6eb..b474893 100644 Binary files a/out/production/fuckJavaGui/autoScore/score.class and b/out/production/fuckJavaGui/autoScore/score.class differ diff --git a/src/autoScore/mainGUI.java b/src/autoScore/mainGUI.java index b5b263a..03e0ad9 100644 --- a/src/autoScore/mainGUI.java +++ b/src/autoScore/mainGUI.java @@ -17,13 +17,14 @@ import java.io.IOException; import static autoScore.answer.readFireAnswer; import static autoScore.question.readFile; import static autoScore.score.getScore; +import static autoScore.score.scoreToTxt; public class mainGUI extends JFrame implements ActionListener { // public static JTextField questionStudent; JTextField questionStudent = new JTextField("问题的位置"); //GridBagLayout questionText =new GridBagLayout(); // questionStudent.setLineWrap(true); - int score; + //public int score; Container c;//创建主容器 private JTextArea question; private JButton A; @@ -96,14 +97,16 @@ public class mainGUI extends JFrame implements ActionListener { public void actionPerformed(ActionEvent e) { //int用来存储现在是第几题 int whatQuestionW = 0; - if (whatQuestionW < 20) { - + int scoreUser =0 ; + if (whatQuestionW < 1) { //int whatQuestionW =0; String str = new String(); if (e.getActionCommand().equals("A")) { str = "A"; - chooseDo(str, whatQuestionW); + /*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser); + whatQuestionW++; + //actionPerformed(ActionEvent e); } /*str = "A"; char ch[] = str.toCharArray(); @@ -124,44 +127,53 @@ public class mainGUI extends JFrame implements ActionListener { }*/ if (e.getActionCommand().equals("B")) { str = "B"; - chooseDo(str, whatQuestionW); + /*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++; // System.out.println(whatQuestionW); } if (e.getActionCommand().equals("C")) { str = "C"; - chooseDo(str, whatQuestionW); + /*scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++; } if (e.getActionCommand().equals("D")) { str = "D"; - chooseDo(str, whatQuestionW); + /* scoreUser=*/chooseDo(str, whatQuestionW,scoreUser);whatQuestionW++; } whatQuestionW++; } else { //这里写最后结果被写入文件夹啊 + try { + scoreToTxt(scoreUser); + } catch (IOException ioException) { + ioException.printStackTrace(); + System.out.println("抛出异常1"); + } } } //按键之后要做的事 - public void chooseDo(String str, int whatQuestionW) { + public int chooseDo(String str, int whatQuestionW,int score) { //str = "A"; char ch[] = str.toCharArray(); char answer = ch[0]; - + //int score = 0; try { - getScore(score, answer, readFireAnswer(whatQuestionW)); + score = getScore(score, answer, readFireAnswer(whatQuestionW)); } catch (IOException ioException) { ioException.printStackTrace(); + System.out.println("抛出异常2"); } whatQuestionW++; - System.out.println(whatQuestionW); + //System.out.println(whatQuestionW); + System.out.println(score); try { questionStudent.setText(readFile(1)); } catch (IOException ioException) { - ioException.printStackTrace(); - } + ioException.printStackTrace();System.out.println("抛出异常3"); + }return score; //mainGUI=new mainGUI(); //actionPerformed(ActionEvent e); + //chooseDo(str,whatQuestionW); } } /*public clstatic void main(String[] args) throws IOException { diff --git a/src/autoScore/score.java b/src/autoScore/score.java index 1507e35..9637b66 100644 --- a/src/autoScore/score.java +++ b/src/autoScore/score.java @@ -1,15 +1,38 @@ +/* + * Copyright (c) 2020 魏遇卿 All Rights Reserved. + * FileName: a.java + * @author: 魏遇卿@date: 2020/6/19 下午8:02@version: 1.0 + * E-mail:358614401@qq.com + * Code with UTF-8 + */ package autoScore; -public class score { - public static int getScore (int score,char choose,char anwser){ - if (choose ==anwser ) { - score++; - return score; - }else { - return score; - } - } - public static void scoreToTxt(/*String name*,*/int score){ +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +public class score { + public static int getScore(int score, char choose, char anwser) { + if (choose == anwser) { + score++; + return score; + } else { + return score; } -} \ No newline at end of file + } + + public static void scoreToTxt(/*String name*,*/int score) throws IOException { + File writename = new File("D:\\WindowsCToD\\fire\\GeneticsMultipleChoice\\Score\\output.txt"); // 相对路径,如果没有则要建立一个新的output。txt文件 + writename.createNewFile(); + BufferedWriter out = new BufferedWriter(new FileWriter(writename)); + out.write(/*name+*/"score:" + score + "\r\n"); // \r\n即为换行 + out.flush(); + out.close(); + } + + /*public static void main(String[] args) throws IOException { + scoreToTxt(5); + }*/ +} +