⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 item.java

📁 一个带界面的在线测试系统
💻 JAVA
字号:
/**
 * Item.java
 * create by ZZ , 2007.12.16
 */
package olts.application;
import javax.swing.*;
import java.awt.*;
/**
 * Item类描述了一条试题
 * @author ZZ
 * @version 1.1
 *
 */
public abstract class Item {
	
	private int id;
	private int difficulty;
	private int timeLimit;
	private String content;
	private String answer;
	private int score;
	private String type;
        private JPanel contentArea;
        private JPanel answerArea;
        private String userAnswer;
	
	public Item(){
		
	}
	
	/**
	 * 用一个试题来初始化这个试题
	 * @param i
	 */
	protected Item(Item i){
		this.setItem(i);
	}
	
	/**
	 * 集团化的设置一个试题
	 */
	protected Item(int id, int diff, int tl, String con,
			String ans, int score, String ty){
		
		this.setId(id);
		this.setDifficulty(diff);
		this.setTimeLimit(tl);
		this.setContent(con);
		this.setAnswer(ans);
		this.setScore(score);
		this.setType(ty);
		
	}
	
	/**
	 * 用另一条试题来初始化这条试题
	 */
	public void setItem(Item i){
		this.setId(i.getId());
		this.setDifficulty(i.getDifficulty());
		this.setTimeLimit(i.getTimeLimit());
		this.setContent(i.getContent());
		this.setAnswer(i.getAnswer());
		this.setScore(i.getScore());
	}
	/**
	 * 设置试题的id
	 */
	public void setId(int i){
		this.id = i;
	}
	
	/**
	 * 获得试题的id
	 */
	public int getId(){
		return this.id;
	}
	
	/**
	 * 设置试题的难易度
	 */
	public void setDifficulty(int d){
		this.difficulty = d;
	}
	
	/**
	 * 获得试题的难易度
	 */
	public int getDifficulty(){
		return this.difficulty;
	}
	
	/**
	 * 设置试题的时间期限
	 */
	public void setTimeLimit(int t){
		this.timeLimit = t;
	}
	
	/**
	 * 获得试题的时间期限
	 */
	public int getTimeLimit(){
		return this.timeLimit;
	}
	
	/**
	 * 设置试题的内容
	 * 
	 */
	public void setContent(String c){
		this.content = c;
	}
	
	/**
	 * 获得试题的内容
	 */
	public String getContent(){
		return this.content;
	}
	
	/**
	 * 设置试题的的标准答案
	 */
	public void setAnswer(String a){
		this.answer = a;
	}
	
	/**
	 * 获得试题的标准答案
	 */
	public String getAnswer(){
		return this.answer;
	}
	
	/**
	 * 设置试题的的分数权重
	 */
	public void setScore(int s){
		this.score = s;
	}
	
	/**
	 * 获得试题的分数权重
	 */
	public int getScore(){
		return this.score;
	}
	
	/**
	 * 设置试题的类型
	 */
	public void setType(String t){
		this.type = t;
	}
	
	/**
	 * 获得试题的类型
	 */
	public String getType(){
		return this.type;
	}
	
	/**
	 * 检查答案对不对,如果和标准答案一致,
	 * 则返回true,否则为false
	 */
	public boolean checkAnswer(String s){
		
		if (this.answer.equals(s) == true){
			return true;
		}
		return false;
		
	}
	
	/**
	 * 该方法用于将本试题在一个JPanel中绘制出来
	 */
	final public void draw(JPanel panel){
		
                //JOptionPane.showMessageDialog(panel,this.getContent());
		this.setPanel(panel);
                
		this.drawContentArea(this.contentArea);
		this.drawAnswerArea(this.answerArea);
                
                panel.add(this.contentArea);
                panel.add(this.answerArea);
	}
	
	public String toString(){
		String s = "";
		s += this.getId() + " ";
		s += this.getDifficulty() + " ";
		s += this.getContent() + " ";
		s += this.getAnswer() + " ";
		s += this.getScore() + " ";
		s += this.timeLimit + " ";
		s += this.type + " ";
		
		return s;
	}
	
        /**
         *该方法生成了题目内容区和答题区,并设置了布局管理器
         */
	protected void setPanel(JPanel panel){
		this.contentArea = new JPanel();
                this.answerArea = new JPanel();
                
                panel.removeAll();
                panel.setLayout(new GridLayout(2,1));

	}
	
	
	/**
	 * 绘制题目内容区域
	 * @param panel
	 */
	protected void drawContentArea(JPanel panel){
		panel.setLayout(new GridLayout(1,1));
                
                JTextArea t = new JTextArea(5,25);
                t.setEditable(false);
                t.setText(this.content);
                t.setTabSize(10);
                t.setLineWrap(true);
                t.setWrapStyleWord(true);
                t.setVisible(true);
                
                JScrollPane jsp = new JScrollPane(t);
                jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
                
                panel.add(jsp);
	}

	/**
	 * 绘制题目的答案区域
	 * @param panel
	 */
	protected void drawAnswerArea(JPanel panel){
		
	}
	
	/**
	 * 传入用户的答案进行暂存
	 * @param ans
	 */
	public void setUserAnswer(String ans){
		this.userAnswer = ans;
		}
	
	/**
	 * 判断用户输入的答案是否正确
	 */
	public boolean isCorrect(){
		if (this.answer.equals(this.userAnswer) == true){
			return true;
			}else{
				return false;
            }
        }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -