?? 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 + -