【发布时间】:2013-12-15 11:44:20
【问题描述】:
我的程序是一个 GUI。我有这种方法,当单击按钮时。它使用 JRadioButtons 动态填充下一个屏幕。
private void setExamButtonActionPerformed(java.awt.event.ActionEvent evt)
{
if(evt.getActionCommand().equals("Set Exam"))
{
CardLayout cL = (CardLayout)cardPanels.getLayout();
cL.show(cardPanels, "setExamPanel");
}
try
{
//InputStream code
String theMessage = myObject.getMessage();
String delims = "(?=(0*([0-9]{1,2}|100)))";
String[] questions = theMessage.split(delims);
System.out.println(Arrays.toString(questions));
for (int j = 1; j < questions.length; j++)
{
settingQuestionBoxes = new JCheckBox(questions[j]);
settingQuestionTextField = new JTextField("");
jPanel1.add(settingQuestionBoxes);
jPanel1.add(settingQuestionTextField);
jPanel1.revalidate();
jPanel1.repaint();
}
//close streams and socket code
}
catch(Exception e)
{
System.out.println(e);
}
}
然后,我从另一个屏幕获得另一个方法,从前一个方法填充的数据将转到该屏幕。
private void setExamQuestionButtonActionPerformed(java.awt.event.ActionEvent evt)
{
if(evt.getActionCommand().equals("Set Exam Question"))
{
ArrayList<JToggleButton> settingQuestionBoxes = new ArrayList<JToggleButton>();
for(JToggleButton questions: settingQuestionBoxes)
{
if(questions.isSelected())
{
System.out.println(questions.getActionCommand());
}
}
CardLayout cL = (CardLayout)cardPanels.getLayout();
cL.show(cardPanels, "instructorPanel");
}
}
所以基本上当我调用这个 System.out.println(questions.getActionCommand()) 时,我试图查看被点击的 JRadiobutton 中的文本。 现在当我运行程序并选择一个按钮时。什么都没有发生。
【问题讨论】:
-
1) 请不要忘记添加“?”提问!有些人在页面中搜索“?”如果“问题”中不存在,则直接转到下一个(实际)问题。 2) 为了尽快获得更好的帮助,请发帖SSCCE。
标签: java swing event-handling jradiobutton