I am trying to create a java function where it takes 2 parameter. One is comma delimited list of string that represent what will be called for radio button. Second is comma delimited list of string that represents the variable respected to 1st parameter.
For example, If I write f1(“apple,banana”, “a,b”), I wanted to make JRadioButton with apple and banana along with a and b being their variable.
Is this possible?
I tried to use split(“,”) but I did not get too far…
Thanks in advance!
EDIT: I came up with following but still now luck..
static void f5(String question, String rbLabel, String rbVar, String help)
{
JOptionPane.showInputDialog(question);
ArrayList<String> rbLabelAL = new ArrayList<String>();
ArrayList<String> rbVarAL = new ArrayList<String>();
String[] token;
String[] token2;
token = rbLabel.split(",");
token2 = rbVar.split(",");
if(token.length == token2.length)
{
for(int i=0;i<token.length;i++)
{
rbLabelAL.add(token[i]);
rbVarAL.add(token2[i]);
}
}
JRadioButton(rbLabelAL(0));
}
Following up on my comment….if you wanted to do something like this, I would suggest creating an
arraylist.Something like….
ArrayList<String> options = new ArrayList<String>();Add in your options….
options.add("apple");Then pass the arraylist into your method and create the radio buttons as such…
JRadioButton(options(i));Of course you would have to iterate through the list to create all buttons.