我没有对我的 jradiobuttons 进行分组,以便用户可以选择多个选项,并且我可以存储在节点数组中......但它只读取一次。代码有什么问题?请赐教
private String[] showGUIForNodeDeletion() {
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(map.size(), 1));
ButtonGroup btnGrp = new ButtonGroup();
final String nodes[] = new String[10];
Set<String> keySet = map.keySet();
for (String name : keySet) {
btnRadio = new JRadioButton(name);
btnRadio.setActionCommand(map.get(name).x + "," + map.get(name).y + "," + name);
//btnGrp.add(btnRadio);
panel.add(btnRadio);
}
btnRadio.addActionListener(new ActionListener() {
int x = 0;
public void actionPerformed(ActionEvent e) {
nodes[x] = ((JRadioButton) e.getSource()).getActionCommand();
System.out.println("Node counting " + x);
x++;
}
});
if (keySet.isEmpty()) {
JOptionPane.showMessageDialog(AnotherGuiSample.this, "Work Space is empty", "Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(AnotherGuiSample.this, panel, "Select node to remove", JOptionPane.INFORMATION_MESSAGE);
}
for(int x = 0; x < nodes.length; x++ )
System.out.println("node is " + nodes[x]);
return nodes;
}