我是一个java 新人今天老师布置了一个作业;不要求用数据库,用 awt 和IO 做一个考试系统;具体要求:CardLayout 布局管理器制作考试系统第一界面;当点击第一界面 的按钮时,触发事件,切换下一道题;选项用单选按钮制作;当考试者 答完题,返回考生的 成绩;考试题目。要用文件读取;现在我界面是没问题,主要是不知道,单选按钮的事件,和 返回答案的界面怎么读取 成绩,希望哪位高人指点,,,,越详细越好,,,如解决问题,100分奉上

解决方案 »

  1.   

    为什么要使用CardLayout?如果题多的话,那岂不是要好多面板?<Qustions>
    <Qustion content="内容",style=boolean/>//content内填写题目内容,style为标志位,代表单选、多选、填空等
        <Condi content="内容"/>
       <Condi content="内容"/>
    </Qustions>
      

  2.   

    用Vector存储所有题目,每道题是一个元素,数据结构如下:class node{
    String title;   //题目
    Vector answer; //答案选项,用Vector存储,以便答案有A~D个,或者A~E个等等
    int no;        //正确答案的编号
    }int anss[]=new int[题目数目];//存放学生做的答案
      

  3.   

    这个程序 有没有可以帮我分析一下的?我执行了,没有运行出来
    ChoiceFile.javaimport java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class ChoiceFile extends Panel implements ItemListener,ActionListener,Runnable
    {
       Button 得到试题文件=null;
       Choice list=null; 
       Socket  socket=null;
       DataInputStream in=null; 
       DataOutputStream out=null; 
       Thread thread=null;
       boolean success=false, isSelected=false;
       int n=0;
       
       public ChoiceFile()
        {
          得到试题文件=new Button("将试题文件添加到下拉列表中");
          得到试题文件.setEnabled(false);
          得到试题文件.addActionListener(this);
          list=new Choice();
          list.add("**********");
          add(得到试题文件);
          add(list);
          list.addItemListener(this);
          thread=new Thread(this);
        }
      public void setSocketConnection(Socket socket,DataInputStream in,DataOutputStream out)
        {
          this.socket=socket;
          this.in=in;
          this.out=out; 
          try {
                thread.start(); 
              }
          catch(Exception ee)
              {
              }
          if(this.socket!=null)
           {
             得到试题文件.setEnabled(true);
           } 
        }
       public void actionPerformed(ActionEvent e)
        {
             try 
               { 
                 out.writeUTF("列出考试文件");
               }
               catch(IOException ee)
               { 
                 success=false;
               }
           
        } 
      public void itemStateChanged(ItemEvent e)
        { 
          n=list.getItemCount();
          if(n>=1&&isSelected==true)
            {
              String listItem=list.getSelectedItem();
               try
                  {
                    out.writeUTF("考试文件的名字:"+listItem);
                    out.writeUTF("请通知考试界面考试用时:");
                  }
               catch(IOException ee)
                  {
                  }
            }         
       }
      public String 得到选择的文件名()
       {
        return list.getSelectedItem();
       }
      public void run()
       {
        String s=null;
        list.removeAll();
        while(true)
          { 
            try
               {
                 s=in.readUTF();          
                  if(s.startsWith("考试文件:"))
                     {
                       String listItem=s.substring(s.indexOf(":")+1);
                       list.add(listItem);
                       isSelected=true;
                     }
                   if(s.startsWith("已经全部列出:"))
                     {
                       success=true; 
                       break;
                     }
                   
               }
            catch (Exception ee) 
               {
               }   
          }
    }
    public boolean getSuccess()

       n=list.getItemCount();
       if(n>0&&success==true)
          return true;
       else
          return false;
    }
      

  4.   

    ReadTestquestion.java
    import java.io.*;
    import java.util.*;
    public class ReadTestquestion
    {  String filename="",         
       correctAnswer="",           
       testContent="" ,            
       selection="" ;              
       int score=0;               
       long time=0;               
       boolean 完成考试=false;    
       File f=null;
       FileReader in=null;
       BufferedReader 读取=null;
      public void setFilename(String name)
          {   filename=name; 
               
               
                score=0;
                selection="";
              try { 
                    if(in!=null&&读取!=null)
                      {
                         in.close();             
                         读取.close();
                      }
                    f=new File(filename);
                    in=new FileReader(f);
                    读取=new BufferedReader(in);            
                    correctAnswer=(读取.readLine()).trim(); 
                    String temp=(读取.readLine()).trim()  ; 
                    StringTokenizer token=new StringTokenizer(temp,":");
                    int hour=Integer.parseInt(token.nextToken()) ;      
                    int minute=Integer.parseInt(token.nextToken());    
                    int second=Integer.parseInt(token.nextToken());    
                    time=1000*(second+minute*60+hour*60*60);           
                   
                  }
               catch(Exception e)
                  {
                    testContent="没有选择试题";
                  }  
          }
      public String getFilename()
          { 
             return filename;
          }
      public long getTime()
          {
             return time;
          }
      public void set完成考试(boolean b)
          {
            完成考试=b;
          }
      public boolean get完成考试()
          {
            return 完成考试;
          } 
      public String getTestContent()  
            { try {  
                     String s=null;
                     StringBuffer temp=new StringBuffer();
                   if(读取!=null)                       
                      {
                       while((s=读取.readLine())!=null) 
                         { 
                           if(s.startsWith("**")) 
                               break;
                           temp.append("\n"+s);
                           if(s.startsWith("endend")) 
                            {
                              in.close();             
                              读取.close();  
                              完成考试=true;         
                            }
                         testContent=new String(temp);  
                       }
                      }
                   else
                      {
                         testContent=new String("没有选择试题");
                      } 
                  } 
              catch(Exception e)
                  { 
                     testContent="试题内容为空,考试结束!!";
                  }
              return testContent;
            }
      public void setSelection(String s)
            {  
               selection=selection+s; 
            }
      public int getScore()
            {  score=0;
               int length1=selection.length();   
               int length2=correctAnswer.length();
               int min=Math.min(length1,length2);
               for(int i=0;i<min;i++)
                  { try{  
                        if(selection.charAt(i)==correctAnswer.charAt(i))
                              score++;
                       }
                    catch(StringIndexOutOfBoundsException e) 
                       { 
                          i=0;
                       }
                  }
               return score;
            }
       public String getMessages()
            {
              int length1=selection.length();  
              int length2=correctAnswer.length();
              int length=Math.min(length1,length2);
              String message="正确答案:"+correctAnswer.substring(0,length)+"\n"+
                             "你的回答:"+selection+"\n";
              return message;
            }
       
    }
      

  5.   

    ClientBS.java
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.applet.*;
    public class ClientBS extends Applet implements ActionListener
    {
      Button     开始测试=null;
      Label      提示条1=null,提示条2=null;
      Socket  socket=null;
      DataInputStream in=null; 
      DataOutputStream out=null; 
      ChoiceFile 选择试题文件界面=null;
      ClientTestArea 考试界面=null;
      Panel west, center;  public void init() 
       {
        setLayout(new BorderLayout()); 
        开始测试    =new Button("开始考试");
        开始测试.addActionListener(this);
        选择试题文件界面=new ChoiceFile();
        选择试题文件界面.setVisible(false);
        考试界面=new ClientTestArea();
        考试界面.setVisible(false);
        提示条1=new Label("正在连接到服务器,请稍等...");
        提示条2=new Label("选择一个文件后,单击"+开始测试.getLabel()+"按钮");
        提示条2.setVisible(false);
        Panel H1= new Panel();        
        H1.add(提示条1);
        Panel H2= new Panel(); 
        H2.add(提示条2);
        Panel H3= new Panel(); 
        H3.add(选择试题文件界面);
        west=new Panel();
        center=new Panel();
        west.setLayout(new GridLayout(3,1));
        west.add(H1);
        west.add(H2);
        west.add(H3);
        center.setLayout(new BorderLayout());
        center.add(开始测试,BorderLayout.NORTH);
        center.add(考试界面,BorderLayout.CENTER);
        add(west,BorderLayout.WEST);
        add(center,BorderLayout.CENTER);
        setVisible(true);
        setBounds(60,40,660,460);
        validate();
       }
    public void start()
       {
         if(socket!=null&&in!=null&&out!=null)
            {  try
                  {
                    socket.close();
                    in.close(); 
                    out.close();
                    考试界面.setVisible(false);
                  }
              catch(Exception ee)
                  {
                   
                  }
            }
         try
            {
             socket = new Socket(this.getCodeBase().getHost(), 6666);
             in=new DataInputStream(socket.getInputStream());
             out=new DataOutputStream(socket.getOutputStream());
            }
         catch (IOException ee)
            { 
              提示条1.setText("连接失败");
            }
         if(socket!=null)
            {
             InetAddress address=socket.getInetAddress();
             提示条1.setEnabled(true);
             提示条1.setText("您连接:"+address+"成功");
             选择试题文件界面.setVisible(true);
             选择试题文件界面.validate();
             选择试题文件界面.setSocketConnection(socket,in,out);
             提示条2.setVisible(true);
             west.validate();
             validate();
            } 
       } 
      
    public void stop()
       {
         try 
             {
               socket.close();
             }
         catch(IOException e)
             {
              this.showStatus(e.toString());
             }
       }
    public void actionPerformed(ActionEvent e)
    {  
        if(e.getSource()==开始测试)
          {
             if(选择试题文件界面.getSuccess())
                 { 
                   考试界面.setSocketConnection(socket,in,out);
                   考试界面.setVisible(true);
                   考试界面.set试题显示区("你选择了试题:"+选择试题文件界面.得到选择的文件名());
                   center.validate();
                   validate();
                 }
           
          }
        
      }