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

📄 blanktestquestionentryframe.java

📁 简单的在线考试系统 提供添加修改 考试等操作
💻 JAVA
字号:
package olts;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.util.HashMap;

import javax.swing.BorderFactory;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class BlankTestQuestionEntryFrame extends JInternalFrame {
	/*this class is the GUI class for user to insert an blank question 
	 * into the database.
	 */

	public static final long serialVersionUID = 1L;

	private HashMap<String, JTextField> fields;
	//current TestQuestionEntry information set by Online application
	private TestQuestionEntry question;
	//panels to organize GUI
	private JPanel leftPanel;
	private JPanel rightPanel;
	//static integers used to determine new window positions
	private static int xOffset=0;
	private static int yOffset=0;
	private static final String id="试题编号:";
	private static final String content="试题内容:";
	private static final String answer="试题答案:";
	private static final String difficulty="试题难度:";
	private static final String score="试题分值:";
	private static final String timelimited="答题时限:";
	//constructor to initiate the GUI interface
	public BlankTestQuestionEntryFrame(){
		super("试题信息表单",true,true,true);
		fields=new HashMap<String, JTextField>();
		leftPanel=new JPanel();
		rightPanel=new JPanel();
		leftPanel.setLayout(new GridLayout(10,1,0,5));
		rightPanel.setLayout(new GridLayout(10,1,0,5));
		
		createRow(id);
		createRow(content);
		createRow(answer);
		createRow(difficulty);
		createRow(score);
		createRow(timelimited);
		
		Container container=getContentPane();
		container.add(leftPanel,BorderLayout.WEST);
		container.add(rightPanel,BorderLayout.CENTER);
		
		setBounds(xOffset,yOffset,800,350);
		//xOffset=(xOffset+30)%300;
		//yOffset=(yOffset+30)%300;		
	}

	public void setTestQuestionEntry(TestQuestionEntry inputQuestion){
		/*set TestQuestionEntry then use its propertiesto
		 *  place data in each JTextField
		 */
		question=inputQuestion;
		setField(id,question.getID());
		setField(content,question.getContent());
		setField(answer,question.getAnswer());
		setField(difficulty,question.getDifficulty());
		setField(score,question.getScore());
		setField(timelimited,question.getTimelimited());		
	}
	public TestQuestionEntry getTestQuestionEntry(){
		/*store TestQuestionEntry data from GUI and return it
		 * 
		 */
		question.setID(getField(id));
		question.setContent(getField(content));
		question.setAnswer(getField(answer));
		question.setScore(getField(score));
		question.setDifficulty(getField(difficulty));
		question.setTimelimited(getField(timelimited));
		return question;		
	}
	private void createRow(String name){
		/*utility method used by container to create one row
		 * 	in GUI containing JLabel and JTextField 
		 */
		JLabel label=new JLabel(name,SwingConstants.LEFT);
		label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
		leftPanel.add(label);
		
		JTextField field=new JTextField(250);
		rightPanel.add(field);
		fields.put(name, field);		
	}
	private void setField(String fieldName,String value){
		/*set text JTextField by specifying field's 
		 * name and value
		 */
		JTextField field=(JTextField)fields.get(fieldName);
		field.setText(value);		
	}
	private String getField(String fieldName){
		//get text text JTextField by specifying field's name
		JTextField field=(JTextField)fields.get(fieldName);
		return field.getText();		
	}
}

⌨️ 快捷键说明

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