factualpanel.java

来自「考试系统」· Java 代码 · 共 107 行

JAVA
107
字号
/*
 * Created on 2004-4-29
 *
 * To change the template for this generated file go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
package gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import paper.*;

import javax.swing.*;

/**
 * @author SpiritRain
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class FactualPanel extends QuestionPanel {
	private JComponent jComponentAnswer;

	/**
	 * 
	 */
	public FactualPanel(boolean permit) {
		super(permit);
		jPanelAns.add(new JLabel("AbstractAnswer: "));
		if (permit){
			JComboBox jcb = new JComboBox();
			jComponentAnswer = new JComboBox();
			((JComboBox)jComponentAnswer).setEditable(true);
			jPanelAns.add(jComponentAnswer);
			JButton jButtonAdd = new JButton("Add AbstractAnswer");
			jButtonAdd.addActionListener(new ActionListener(){

				public void actionPerformed(ActionEvent arg0) {
					((JComboBox)jComponentAnswer).addItem(((JComboBox)jComponentAnswer).getSelectedItem());
					
				}});
			jPanelAns.add(jButtonAdd);
		}
		else{
			jComponentAnswer = new JTextField(20);
			jPanelAns.add(jComponentAnswer);
		}
		jPanelAns.add(new JLabel("Score:"));
		jPanelAns.add(jTextFieldAnsScore);

		jPanelAns.add(jButtonHint);
	}

	public AbstractAnswer createNewAnswer() {
		String[] str;
		if (permit){
			str = new String[((JComboBox)jComponentAnswer).getItemCount()];
			for (int i = 0; i < str.length ; i++){
				str[i] = (String)(((JComboBox)jComponentAnswer).getItemAt(i));
			}
		}
		else{
			str = new String[1];
			str[0] = ((JTextField)jComponentAnswer).getText();
		}
		AbstractAnswer ans = new FactualAns(str);
		return ans;
	}
	public void setAnswer(AbstractAnswer ans) {
		if (permit) {
			((JComboBox) jComponentAnswer).removeAllItems();
			if (ans == null) {
				((JTextField) jComponentAnswer).setText("");
			} else {
				for (int i = 0; i < ans.getAnsCount(); i++) {
					((JComboBox) jComponentAnswer).addItem(ans.getAnswer(i));
				}
			}
		} else {
			if (ans == null) {
				((JTextField) jComponentAnswer).setText("");
			} else {
				((JTextField) jComponentAnswer).setText(
					ans.getAnswer(0).toString());
			}
		}
		jTextFieldAnsScore.setText("" + question.getQuestionScore());
	}

	/* (non-Javadoc)
	 * @see gui.QuestionPanel#createNewQuestion()
	 */
	public AbstractQuestion createNewQuestion(int diff) {
		FactualASet fas = new FactualASet(createNewAnswer());
		FactualQuestion fq =
			new FactualQuestion(
				this.jTextAreaQuestion.getText(),
				fas,
				this.jTextAreaHint.getText(),
				Integer.parseInt(this.jTextFieldAnsScore.getText()),
				diff);
		return fq;
	}

}

⌨️ 快捷键说明

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