import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
class FileName implements FilenameFilter //负责列出指定扩展名的文件
{
String str=null;
FileName(String s)
{
str=" . "+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable
{
Choice list=null; //选择试题的下拉式列表
JTextArea 试题显示区=null,消息区=null;
JCheckBox box[]; //选择答案
JButton 提交该题答案, 读取下一题,查看分数;
ReadTestquestion 读取试题=null; //负责读取试题和判分的对象
JLabel welcomeLabel=null; //欢迎语标签
Thread countTime=null; //计时器
long time=0; //考试用时
JTextField timeShow=null; //显示剩余时间
boolean 是否关闭计时器=false,
是否暂停计时=false;
JButton 暂停或继续计时 =null;
public TestArea()
{
list=new Choice();
//错误可能在这里,错误可能在这里,错误可能在这里,错误可能在这里,错误可能在这里
String shiti =System.getProperty(" user.dir");
File dir=new File(shiti);
FileName fileTxt=new FileName("txt");
String fileName[]=dir.list(fileTxt);//列出当前目录中的文件
for(int i=0;i<fileName.length;i++)
{
list.add(fileName[i]);
}
试题显示区=new JTextArea(15,12);
试题显示区.setLineWrap(true);//文本区自动回行
试题显示区.setWrapStyleWord(true);//回行时,不把同一个单词分开
试题显示区.setFont(new Font("TimesRoman",Font.PLAIN,14));
试题显示区.setForeground(Color.blue);
消息区=new JTextArea(8,8);
消息区.setForeground(Color.blue);
消息区.setLineWrap(true);
消息区.setWrapStyleWord(true); countTime=new Thread(this);
String s[]={"A", "B","C","D"}; //创建计时器线程
box=new JCheckBox[4];
for(int i=0;i<4;i++)
{
box[i]=new JCheckBox(s[i]);
}
暂停或继续计时 =new JButton("暂停计时");
暂停或继续计时.addActionListener(this);
提交该题答案=new JButton("提交该题答案");
提交该题答案.setForeground(Color.blue);
读取下一题=new JButton("读取下一题");
读取下一题.setForeground(Color.blue );
查看分数=new JButton("查看分数");
查看分数.setForeground(Color.blue);
提交该题答案.setEnabled(false);
提交该题答案.addActionListener(this);
读取下一题.addActionListener(this);
查看分数.addActionListener(this);
list.addItemListener(this);
读取试题=new ReadTestquestion();
JPanel pAddbox=new JPanel();
for(int i=0;i<4;i++)
{
pAddbox.add(box[i]);
}
Box boxH1=Box.createVerticalBox(),//创建一个垂直型Box容器,容器中的组件排列在一列中
boxH2=Box.createVerticalBox(),
baseBox=Box.createHorizontalBox();// 创建一个水平型Box容器,容器中的组件排列在一行中
boxH1.add(new JLabel("选择试题文件"));
boxH1.add(list);
boxH1.add(new JScrollPane(消息区));
boxH1.add(查看分数);
timeShow=new JTextField(20);
timeShow.setHorizontalAlignment(SwingConstants.RIGHT);//显示剩余时间
timeShow.setEditable(false);
JPanel p1=new JPanel();
p1.add(new JLabel("剩余时间: "));
p1.add(timeShow); //添加显示计时的文本条
p1.add(暂停或继续计时);
boxH1.add(p1);
boxH2.add(new JLabel("试题内容: "));
boxH2.add(new JScrollPane(试题显示区));
JPanel p2=new JPanel();
p2.add(pAddbox); //添加答案选项A,B,C,D。
p2.add(提交该题答案);
p2.add(读取下一题);
boxH2.add(p2);
baseBox.add(boxH1);
baseBox.add(boxH2);
setLayout(new BorderLayout());
add(baseBox,BorderLayout.CENTER);
welcomeLabel=new JLabel("欢迎考试,提高英语水平",JLabel.CENTER);
welcomeLabel.setFont(new Font("隶书",Font.PLAIN,24));
welcomeLabel.setForeground(Color.blue);
add(welcomeLabel,BorderLayout.NORTH);
}
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
class FileName implements FilenameFilter //负责列出指定扩展名的文件
{
String str=null;
FileName(String s)
{
str=" . "+s;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
public class TestArea extends JPanel implements ActionListener,ItemListener,Runnable
{
Choice list=null; //选择试题的下拉式列表
JTextArea 试题显示区=null,消息区=null;
JCheckBox box[]; //选择答案
JButton 提交该题答案, 读取下一题,查看分数;
ReadTestquestion 读取试题=null; //负责读取试题和判分的对象
JLabel welcomeLabel=null; //欢迎语标签
Thread countTime=null; //计时器
long time=0; //考试用时
JTextField timeShow=null; //显示剩余时间
boolean 是否关闭计时器=false,
是否暂停计时=false;
JButton 暂停或继续计时 =null;
public TestArea()
{
list=new Choice();
//错误可能在这里,错误可能在这里,错误可能在这里,错误可能在这里,错误可能在这里
String shiti =System.getProperty(" user.dir");
File dir=new File(shiti);
FileName fileTxt=new FileName("txt");
String fileName[]=dir.list(fileTxt);//列出当前目录中的文件
for(int i=0;i<fileName.length;i++)
{
list.add(fileName[i]);
}
试题显示区=new JTextArea(15,12);
试题显示区.setLineWrap(true);//文本区自动回行
试题显示区.setWrapStyleWord(true);//回行时,不把同一个单词分开
试题显示区.setFont(new Font("TimesRoman",Font.PLAIN,14));
试题显示区.setForeground(Color.blue);
消息区=new JTextArea(8,8);
消息区.setForeground(Color.blue);
消息区.setLineWrap(true);
消息区.setWrapStyleWord(true); countTime=new Thread(this);
String s[]={"A", "B","C","D"}; //创建计时器线程
box=new JCheckBox[4];
for(int i=0;i<4;i++)
{
box[i]=new JCheckBox(s[i]);
}
暂停或继续计时 =new JButton("暂停计时");
暂停或继续计时.addActionListener(this);
提交该题答案=new JButton("提交该题答案");
提交该题答案.setForeground(Color.blue);
读取下一题=new JButton("读取下一题");
读取下一题.setForeground(Color.blue );
查看分数=new JButton("查看分数");
查看分数.setForeground(Color.blue);
提交该题答案.setEnabled(false);
提交该题答案.addActionListener(this);
读取下一题.addActionListener(this);
查看分数.addActionListener(this);
list.addItemListener(this);
读取试题=new ReadTestquestion();
JPanel pAddbox=new JPanel();
for(int i=0;i<4;i++)
{
pAddbox.add(box[i]);
}
Box boxH1=Box.createVerticalBox(),//创建一个垂直型Box容器,容器中的组件排列在一列中
boxH2=Box.createVerticalBox(),
baseBox=Box.createHorizontalBox();// 创建一个水平型Box容器,容器中的组件排列在一行中
boxH1.add(new JLabel("选择试题文件"));
boxH1.add(list);
boxH1.add(new JScrollPane(消息区));
boxH1.add(查看分数);
timeShow=new JTextField(20);
timeShow.setHorizontalAlignment(SwingConstants.RIGHT);//显示剩余时间
timeShow.setEditable(false);
JPanel p1=new JPanel();
p1.add(new JLabel("剩余时间: "));
p1.add(timeShow); //添加显示计时的文本条
p1.add(暂停或继续计时);
boxH1.add(p1);
boxH2.add(new JLabel("试题内容: "));
boxH2.add(new JScrollPane(试题显示区));
JPanel p2=new JPanel();
p2.add(pAddbox); //添加答案选项A,B,C,D。
p2.add(提交该题答案);
p2.add(读取下一题);
boxH2.add(p2);
baseBox.add(boxH1);
baseBox.add(boxH2);
setLayout(new BorderLayout());
add(baseBox,BorderLayout.CENTER);
welcomeLabel=new JLabel("欢迎考试,提高英语水平",JLabel.CENTER);
welcomeLabel.setFont(new Font("隶书",Font.PLAIN,24));
welcomeLabel.setForeground(Color.blue);
add(welcomeLabel,BorderLayout.NORTH);
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货