📄 singlechoiceitemdisplay.java
字号:
/*
* SingleChoiceItemDisplay.java
*
* MSE06B班张智力的实验报告
*
* 2006年12月10日
*/
package olts.display;
import olts.AnswerSheet;
import java.awt.GridLayout;
import javax.swing.*;
/**
* SingleChoiceItemDisplay类,继承了JPanel,生成显示单选题的JPanel
*/
public class SingleChoiceItemDisplay extends JPanel {
/**
* jLabel,用于显示试题的题目
*/
private JLabel jLabel = null;
/**
* JRadioButton,用于显示及接收选项A
*/
private JRadioButton jRadioButton = null;
/**
* JRadioButton,用于显示及接收选项B
*/
private JRadioButton jRadioButton1 = null;
/**
* JRadioButton,用于显示及接收选项C
*/
private JRadioButton jRadioButton2 = null;
/**
* JRadioButton,用于显示及接收选项D
*/
private JRadioButton jRadioButton3 = null;
/**
* answerSheet对象,该Display的数据模型
*/
private AnswerSheet answerSheet;
/**
* parent,记录本JPanel所在的frame父容器,方便回调父容器中的响应代码。
*/
private MainFrame parent;
/**
* This method initializes jRadioButton
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton() {
if (jRadioButton == null) {
jRadioButton = new JRadioButton();
jRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
answerSheet.setAnswer("A");
answerResponse(answerSheet.getTestId(), "A");
}
});
}
return jRadioButton;
}
/**
* This method initializes jRadioButton1
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton1() {
if (jRadioButton1 == null) {
jRadioButton1 = new JRadioButton();
jRadioButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
answerSheet.setAnswer("B");
answerResponse(answerSheet.getTestId(), "B");
}
});
}
return jRadioButton1;
}
/**
* This method initializes jRadioButton2
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton2() {
if (jRadioButton2 == null) {
jRadioButton2 = new JRadioButton();
jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
answerSheet.setAnswer("C");
answerResponse(answerSheet.getTestId(), "C");
}
});
}
return jRadioButton2;
}
/**
* This method initializes jRadioButton3
*
* @return javax.swing.JRadioButton
*/
private JRadioButton getJRadioButton3() {
if (jRadioButton3 == null) {
jRadioButton3 = new JRadioButton();
jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
answerSheet.setAnswer("D");
answerResponse(answerSheet.getTestId(), "D");
}
});
}
return jRadioButton3;
}
private void answerResponse(int i, String s){
parent.answerResponse(i, s);
}
/**
* This is the default constructor
*/
public SingleChoiceItemDisplay(AnswerSheet answerSheet, MainFrame jf) {
super();
this.answerSheet = answerSheet;
this.parent = jf;
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
jLabel = new JLabel();
String temp[] = answerSheet.getItem().content.split("/");
jLabel.setText(answerSheet.getTestId() + ". " + temp[0] + "(" + answerSheet.getScore() + "分)");
GridLayout gridLayout = new GridLayout();
gridLayout.setRows(5);
gridLayout.setHgap(1);
gridLayout.setVgap(1);
gridLayout.setColumns(1);
this.setLayout(gridLayout);
this.setSize(400, 200);
this.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED));
ButtonGroup group = new ButtonGroup();
group.add(getJRadioButton());
group.add(getJRadioButton1());
group.add(getJRadioButton2());
group.add(getJRadioButton3());
jRadioButton.setText("A. " + temp[1]);
jRadioButton1.setText("B. " + temp[2]);
jRadioButton2.setText("C. " + temp[3]);
jRadioButton3.setText("D. " + temp[4]);
this.add(jLabel, null);
this.add(getJRadioButton(), null);
this.add(getJRadioButton1(), null);
this.add(getJRadioButton2(), null);
this.add(getJRadioButton3(), null);
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -