我稍微改了改自己再改改吧import java.io.*;
import javax.swing.*;
import java.util.*;public class Mini {
        Vector questions = new Vector();
        Vector answers = new Vector();
        public void questions() {
                String record1 = null;
                try {
                        FileReader fr = new FileReader("questions.txt");
                        BufferedReader br = new BufferedReader(fr);
                        record1 = new String();
                        while((record1 = br.readLine())!=null) {
                                questions.addElement(record1);
                        }
                        br.close();
                        fr.close();
                } catch (IOException e) {
                        System.err.println("got an error!");
                        e.printStackTrace();
                }
        }        public void answer() {
                String record2 = null;
                try {
                        FileReader fr = new FileReader("answers.txt");
                        BufferedReader br = new BufferedReader(fr);
                        record2 = new String();
                        while((record2 = br.readLine())!=null) {
                                answers.addElement(record2);
                        }
                        br.close();
                        fr.close();
                } catch (IOException e) {
                        System.err.println("got an error!");
                        e.printStackTrace();
                }
        }        void begin()
        {
                for ( int i = 0; i< questions.size();i++)
                {
                        String result = JOptionPane.showInputDialog(questions.elementAt(i));
                        if (result.compareToIgnoreCase((String)answers.elementAt(i))== 0)
                        {
                                result = "good";
                        } else {
                                result = "sorry";
                        }
                        JOptionPane.showMessageDialog(null,
                                        result,"Are you right?",JOptionPane.INFORMATION_MESSAGE);
                }
        }        public static void main(String args[]) {
                Mini mi=new Mini();
                mi.questions();
                mi.answer();
                int judge = 0;
                while(true)
                {
                        String result = JOptionPane.showInputDialog("Enter -1 to quit");
                        try {
                                judge = Integer.parseInt(result);
                        } catch (NumberFormatException e) {                        }
                        if (judge == -1) break;
                        mi.begin();
                }
                System.exit(0);
        }
}

解决方案 »

  1.   

    谢谢高手!!!!小弟感激不尽!!!!你是我的大恩人,有空我想亲自来谢谢你.如果有什么帮忙,而我又能帮的上忙的话我一定会帮你的.我知道除了谢谢就做不到什么了,但是千言万语都在一句谢谢中.高人你能把你的qq和email给我吗??我还有很多东西想请教你不知道你是否愿意呢??希望你能够过上一个愉快的圣诞节.