我想在第二帧中动态创建单选按钮,并且一旦选择了按钮,就可以根据输入更改单选按钮的背景颜色。我的问题是我可以创建第二帧,但是,不会创建单选按钮。感谢任何帮助!
这是我的代码
public class ColorRadioButtons extends ReadStoreShow{
private JFrame f = new JFrame("Colors");
public ColorRadioButtons() {
JPanel panel2 = new JPanel(new GridLayout(1,2));
panel2.setBorder(new EmptyBorder(10,10,10,10));
ButtonGroup radioButtonGroup = new ButtonGroup();
for (int i=0; i<subListOfColors.size(); i++) {
Colors a = subListOfColors.get(i);
String s = a.getColorName();
JRadioButton jrb = new JRadioButton(s);
radioButtonGroup.add(jrb);
panel2.add(jrb);
}
add(panel2, BorderLayout.NORTH);
f.pack();
f.setTitle("Colors Radio Buttons");
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}
答案 0 :(得分:3)
我认为这一行有一些错误(与文本中的问题无关):if (number >= 10 || number <= 20)
。如果我没有弄错的话,就像if(true)
或者if
一样。我认为你的意思是&&
而不是||
。