📄 choiceitem.java
字号:
package viewer;
import javax.swing.JPanel;
import java.awt.Rectangle;
import java.awt.Color;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.JRadioButton;
import javax.swing.Box;
import java.awt.SystemColor;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import model.persistency.PersistentItem;
import javax.swing.JTextField;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;
import java.awt.Point;
import java.awt.Dimension;
/**
* <p>Title: </p>
* 选择题框架
* <p>Description: </p>
* 对于选择题调用选择题框架,对用户选择的答案记录在父框架的答案属性中
*/
public class ChoiceItem extends TestFrame{
PersistentItem item;// 当前题目
ButtonGroup g = new ButtonGroup();
JRadioButton aRadioButton = new JRadioButton();
JRadioButton dRadioButton = new JRadioButton();
JRadioButton bRadioButton = new JRadioButton();
JRadioButton cRadioButton = new JRadioButton();
JButton jButton1 = new JButton();
/**
* constructor
* @param it PersistentItem 当前题目
*/
public ChoiceItem(PersistentItem it) {
super(it);
this.item = it;
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private void jbInit() throws Exception {
setSize(new Dimension(525, 440));
aRadioButton.setText("A");
aRadioButton.setBounds(new Rectangle(29, 240, 43, 23));
aRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("A",aRadioButton);}
});//匿名类
cRadioButton.setText("C");
cRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("C",cRadioButton);}
});
cRadioButton.setBounds(new Rectangle(129, 240, 43, 23));
bRadioButton.setText("B");
bRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("B",bRadioButton);}
});
bRadioButton.setBounds(new Rectangle(79, 240, 43, 23));
dRadioButton.setText("D");
dRadioButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
trace("D",dRadioButton);}
});
dRadioButton.setBounds(new Rectangle(179, 240, 43, 23));
jButton1.setText("jButton1");
g.add(aRadioButton); g.add(bRadioButton);
g.add(cRadioButton); g.add(dRadioButton);
this.getContentPane().add(bRadioButton);
this.getContentPane().add(dRadioButton);
this.getContentPane().add(cRadioButton);
this.getContentPane().add(aRadioButton);
this.getContentPane().add(jButton1);
}
/**
* 记录点击的题目,赋给父类答案属性
* @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 + -