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

📄 answerpane.java

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

import javax.swing.*;

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

public class AnswerPane extends JInternalFrame implements ActionListener{
	/**this classs is the GUI interface that coupled with
	 * TestFrame for user to  answer question . 
	 */
	public static int num=1;
	private static final long serialVersionUID = 1L;
	private JPanel answer;
	private Container container;
	private String singleChoice;
	private String tfChoice;
	private static boolean[]singleisChoice =new boolean[4];
	private static boolean[]tfisChoice =new boolean[2];
	private static String type;
	private static String blank;
	JTextField field=new JTextField(13);
	JRadioButton []singlebutton=new JRadioButton[4];
	JRadioButton []truefalsebutton=new JRadioButton[2];
	JButton submit=new JButton("提交");
	//sub=new submitAction();
	
	public AnswerPane(){
		/*constructor to initiate the frame 
		 */
		super("答题卡",true,true,true,true);
		answer=new JPanel();
		JLabel blank=new JLabel("                               ");
		container=getContentPane();       		
		//container.setLayout(arg0);
		GridLayout bord=new GridLayout(1,15);
		container.setLayout(bord);	
		answer.add(submit);
		answer.add(blank);
		submit.addActionListener(this);
		container.add("Center", answer);
		show();
		setBounds(605,0,185,450);
	}
	public void actionPerformed(ActionEvent e){
		/*actionlistener will be invoke when user 
		 * submit the  answer.
		 */
		if(e.getSource()==submit){
			TestLogic logic=new TestLogic();
			try {
				if(type.equals("s")){
				singleisChoice[0]=singlebutton[0].isSelected();
				singleisChoice[1]=singlebutton[1].isSelected();
				singleisChoice[2]=singlebutton[2].isSelected();
				singleisChoice[3]=singlebutton[3].isSelected();
				}else if(type.equals("t")){
					tfisChoice[0]=truefalsebutton[0].isSelected();
					tfisChoice[1]=truefalsebutton[0].isSelected();
				}else if(type.equals("b")){
					blank=field.getText();
				}
				JOptionPane.showMessageDialog(container, "考试得分是:"+logic.getMark());
			} catch (Exception e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}
	public void singleItem(){
		/*
		 * singleItem choice button group
		 */
		singleisChoice =new boolean[4];		
		JLabel questionNum=new JLabel(num+":");
		type="s";
		answer.add(questionNum);
		singlebutton[0]=new JRadioButton("A");
		singlebutton[1]=new JRadioButton("B");
		singlebutton[2]=new JRadioButton("C");
		singlebutton[3]=new JRadioButton("D");
		ButtonGroup group=new ButtonGroup();
		for(int i=0;i<singlebutton.length;i++){
			group.add(singlebutton[i]);
			answer.add(singlebutton[i]);
		}
		num++;
	}
	public void trueItem(){
		/*true or false radiobutton  group
		 */
		type="t";
		JLabel questionNum=new JLabel(num+":",SwingConstants.LEFT);
		JLabel blank=new JLabel("         ");
		answer.add(questionNum);
		truefalsebutton[0]=new JRadioButton("True");
		truefalsebutton[1]=new JRadioButton("False");
		ButtonGroup group=new ButtonGroup();
		for(int i=0;i<truefalsebutton.length;i++){
			group.add(truefalsebutton[i]);
			answer.add(truefalsebutton[i]);
		}
		answer.add(blank);
		num++;		
	}
	public void blankItem(){
		/*
		 * the textfield for user to answer question in an textfield
		 */
		type="b";
		JLabel questionNum=new JLabel(num+":",SwingConstants.LEFT);
		answer.add(questionNum);
		answer.add(field);	
		num++;
	}
	public String singleChoice(){
		/*get the current single choice when user submit 
		 * their answer. 
		 */
		if(singleisChoice[0]){
			singleChoice="A";
		}else if(singleisChoice[1]){
			singleChoice="B";
		}else if(singleisChoice[2]){
			singleChoice="C";
		}else if(singleisChoice[3]){
			singleChoice="D";
		}
		return singleChoice;
	}
	public String tfChoice(){
		/*get the current true false choice when user submit 
		 * their answer. 
		 */
		if(tfisChoice[0]){
			tfChoice="T";
		}else if(tfisChoice[1]){
			tfChoice="F";
		}
		return tfChoice;
	}
	public String blankChoice(){
		/*
		 * the get method for other class to get its values
		 */
		return blank;
	}
	public String getType(){
		/*
		 * the get method for other class to get its values
		 */
		return type;
	}
}

⌨️ 快捷键说明

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