java实现标准化考试系统详解(三)-----考试界面模块化实现及事件处理

本文详细讲解了如何使用Java构建标准化考试系统,将考试界面拆分为多个JPanel组件,包括Questions类、QuestionModel、QuestionHandle、QuestionNumberHandle、ControlHandle等,实现了试题显示、数据处理和倒计时等功能。文章还提到了TimeView类用于倒计时显示,并鼓励读者关注作者的博客获取更多相关教程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


(一)将考试界面分为若干个JPanel组合实现



如图所示我们需要把整个界面大体划分为三个区域,具体分为四个区域,多一个带虚线的倒计时区域。


(二)、具体实现


想要显示试题我们必须先拿到试题,而试题是通过数据库中读出以二维数文本组保存如果直接用的话很不方便,因此我们就需要考虑数据元的创建即试题类(Questions)

1.Questions类:

public class Questions {
	boolean isChoice;//是否为单选题
	boolean isMultipleChoice;//是否为多选题
	boolean isJudgement;//是否为判断题
	String mContext="";//试题内容
	String mChoiceAContext="";//A选项内容
	String mChoiceBContext="";//B选项内容
	String mChoiceCContext="";//C选项内容
	String mChoiceDContext="";//D选项内容
	String mImageName="";//图片名称
	String mCurrectAnswer="";//正确答案
	String mUserAnswer="";//用户答案
	String mApplicable="";//适用工程
	String mType="";//试题类型
	int mID;//初始化数组编号
	
	//设置是否为单选题
	public void setIsChoice(boolean isChoice)
	{
		this.isChoice=isChoice;
	}
	//获取是否为单选题
	public boolean getIsChoice()
	{
		return this.isChoice;
	}
	//设置是否为多选题
	public void setIsMultipleChoice(boolean isMultipleChoice)
	{
		this.isMultipleChoice=isMultipleChoice;
	}
	//获取是否为单选题
	public boolean getIsMultipleChoice()
	{
		return this.isMultipleChoice;
	}
	//设置是否为判断选题
	public void setIsJudgement(boolean isJudgement)
	{
		this.isJudgement=isJudgement;
	}
	//得到是否为判断选题
	public boolean getIsJudgement()
	{
		return this.isJudgement;
	}
	//设置题目内容
	public void setContext(String context)
	{
		this.mContext=context;
	}
	//得到题目内容
	public String getContext()
	{
		return this.mContext;
	}
	//设置图片名字
	public void setImageName(String imageName)
	{
		this.mImageName=imageName;
	}
	//得到图片名字
	public String getImageName()
	{
		return this.mImageName;
	}
	//设置a选项内容
	public void setChoiceAContext(String ChoiceAContext)
	{
		this.mChoiceAContext=ChoiceAContext;
	}
	//得到a选项内容
	public String getChoiceAContext()
	{
		return this.mChoiceAContext;
	}
	//b选项内容
	public void setChoiceBContext(String ChoiceBContext)
	{
		this.mChoiceBContext=ChoiceBContext;
	}
	//得到b选项内容
	public String getChoiceBContext()
	{
		return this.mChoiceBContext;
	}
	//c选项内容
	public void setChoiceCContext(String ChoiceCContext)
	{
		this.mChoiceCContext=ChoiceCContext;
	}
	//得到c选项内容
	public String getChoiceCContext()
	{
		return this.mChoiceCContext;
	}
	//d选项内容
	public void setChoiceDContext(String ChoiceDContext)
	{
		this.mChoiceDContext=ChoiceDContext;
	}
	//得到d选项内容
	public String getChoiceDContext()
	{
		return this.mChoiceDContext;
	}
	//设置正确答案
	public void setCurrectAnswer(String CurrectAnswer)
	{
		this.mCurrectAnswer=CurrectAnswer;
	}
	//得到正确答案
	public String getCurrectAnswer()
	{
		return this.mCurrectAnswer;
	}
	//设置用户答案
	public void setUserAnswer(String userAnswer)
	{
		this.mUserAnswer=userAnswer;
	}
	//得到用户答案
	public String getUserAnswer()
	{
		return this.mUserAnswer;
	}
	//设置适用工程
	public void setApplicable(String applicable)
	{
		this.mApplicable=applicable;
	}
	//得到适用工程
	public String getApplicable()
	{
		return this.mApplicable;
	}
	//设置题型
	public void setType(String type)
	{
		this.mType=type;
	}
	//得到题型
	public String getType()
	{
		return this.mType;
	}
	//设置题目序号
	
	public void setNumber(int number)
	{
		this.mID=number;	
	}
	//得到题目序号
	public int getNumber()
	{
		return this.mID;
	}
}

我们知道试题肯定不止一道因此就需要一个试题数组来存放所有试题,因此我们还需要一个模型来管理所有试题

2.QuestionModel:

public class QuestionModel {
	private Questions[] mQuestions=null;
	int mIndex=0;
	//设置全部试题
	public void setQuestions(Questions[] Questions)
	{
		this.mQuestions=Questions;
	}
	//返回所有试题
	public Questions[] getAllQuestions()
	{
		if(mQuestions==null)
		{
			return null;
		}else if(mQuestions.length==0)
		{
	
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值