📄 truefalseitem.java
字号:
package viewer;
import javax.swing.JRadioButton;
import java.awt.Rectangle;
import model.persistency.PersistentItem;
import javax.swing.ButtonGroup;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.awt.Point;
import java.awt.Dimension;
/**
* <p>Title: </p>
* 判断题框架
* <p>Description: </p>
* 对于判断题调用判断题框架,对用户选择的答案记录在父框架的答案属性中
*/
public class TrueFalseItem extends TestFrame{
PersistentItem item; //当前题目
ButtonGroup g = new ButtonGroup();
JRadioButton trueRadioButton = new JRadioButton();
JRadioButton falseRadioButton = new JRadioButton();
/**
* constructor
* @param it PersistentItem 当前题目
*/
public TrueFalseItem(PersistentItem it) {
super(it);
this.item = it;
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
setSize(new Dimension(525, 440));
setTitle("OLTS System");
trueRadioButton.setText("True");
trueRadioButton.setBounds(new Rectangle(33, 237, 103, 23));
falseRadioButton.setText("False");
falseRadioButton.setBounds(new Rectangle(159, 237, 103, 23));
this.getContentPane().add(trueRadioButton);
this.getContentPane().add(falseRadioButton);
g.add(trueRadioButton);
g.add(falseRadioButton);
trueRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("T",trueRadioButton);}
});
falseRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("F",falseRadioButton);}
});
}
/**
* 如果选择此按钮,将答案记录于父类答案属性中
* @param a String 按钮代表的字符串
* @param cb JRadioButton 按钮名称
*/
private void trace(String a, JRadioButton cb){
if(cb.isSelected())
super.answer = a;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -