一个小的考试系统(有待完善),其中有些问题请教过高手,现和大家分享

小弟初学,其中有些问题自己处理不了,请教过高手,现在和大家一起分享。另外程序中有什么不当之处或需要添加的,请多指点,谢谢!!!!!



import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class FileIo implements ItemListener,ActionListener{
Frame MyFrame=new Frame();
Button btn1=new Button("下一题");
String s="";
int i=0;
TextArea ta=new TextArea(10,50);
Button btn=new Button("开始");
TextField text=new TextField("02:00:00",25);
CheckboxGroup checkboxgroup=new CheckboxGroup();
Checkbox p1=new Checkbox("A",false,checkboxgroup);
Checkbox p2=new Checkbox("B",false,checkboxgroup);
Checkbox p3=new Checkbox("C",false,checkboxgroup);
Checkbox p4=new Checkbox("D",false,checkboxgroup);
FileReader fr;
BufferedReader br;
public FileIo()
{
try{
fr=new FileReader("text.txt");//在当前目录下新建一存题的文件text.txt
br=new BufferedReader(fr);
}catch(IOException e){}
text.setEditable(false);
btn1.setEnabled(false);
MyFrame.setLayout(new FlowLayout());
MyFrame.add(ta);
MyFrame.add(btn);
MyFrame.add(p1);
MyFrame.add(p2);
MyFrame.add(p3);
MyFrame.add(p4);
MyFrame.add(btn1);
MyFrame.add(text);
MyFrame.setSize(300,300);
MyFrame.setVisible(true);
btn1.addActionListener(this);
MyFrame.addWindowListener(new HandleWin());
p1.addItemListener(this);
p2.addItemListener(this);
p3.addItemListener(this);
p4.addItemListener(this);
btn.addActionListener(new ButtonAct());
}
public void itemStateChanged(ItemEvent e)//答题
{
Checkbox checkbox=(Checkbox)e.getSource();
String label=checkbox.getLabel();
try{
if(e.getStateChange()==ItemEvent.SELECTED){
PrintWriter input=new PrintWriter(new FileWriter("key.txt",true));//在当前目录下新建一存答案文件key.txt
i++;
input.println(i+"."+label);
input.close();
}
}catch(IOException ioe){}
}
class ButtonAct implements ActionListener//时间开始
{
public void actionPerformed(ActionEvent e)
{
MyThread thread=new MyThread();
thread.start();
btn1.setEnabled(true);
try{
while((s=br.readLine())!=null)
{
if(s.equals("#"))
break;
ta.append(s+'\n');
}
}catch(IOException ioe){}
btn.setEnabled(false);
}
}
class MyThread extends Thread//时间线程
{
public void run()
{
int hour;
int mintue;
int sceond;
for(int time=7199;time>=1;time--)
{
hour=time/3600;
mintue=(time-hour*3600)/60;
sceond=time-hour*3600-mintue*60;
text.setText(hour+":"+mintue+":"+sceond);
try{
Thread.sleep(1000);
}catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
public void actionPerformed(ActionEvent e)//读题
{
if(e.getActionCommand()=="下一题")
{
checkboxgroup.setSelectedCheckbox(null);
ta.setText("");
try{
while((s=br.readLine())!=null)
{
if(s.equals("#"))
break;
if(s.equals("答题结束"))
btn1.setVisible(false);
ta.append(s+'\n');
}
}catch(IOException ioe){}
}
}
class HandleWin extends WindowAdapter//关闭窗口
{
public void windowClosing(WindowEvent e)
{
(e.getWindow()).dispose();
System.exit(0);
}
}
public static void main(String args[])
{
new FileIo();
}

}

你可能感兴趣的:(多线程,thread)