I am creating a survey form using java swing. I'm loading questions and answers from my database to the view and I'm dynamically loading radio buttons (answers) to the view.
I created a 2D array to generate JRadioButton objects.
JRadioButton[][] rdbtnanswer;
public method() {
int ans_yval = 0;
for (int i = 0; i < questions.getNumberOfQuestions(); i++) {
String questionnair = questions.getQuestion(i);
Vector<Answers> vector_answers = questions.getAnswer(questionnair);
ButtonGroup group = new ButtonGroup();
rdbtnanswer = new JRadioButton[questions.getNumberOfQuestions()][vector_answers.size()];
for (int v = 0; v < vector_answers.size(); v++) {
rdbtnanswer[i][v] = new JRadioButton(vector_answers.get(v).getAnswers());
rdbtnanswer[i][v].setBounds(31, 170+ans_yval, 236, 23);
contentPane.add(rdbtnanswer[i][v]);
group.add(rdbtnanswer[i][v]);
ans_yval = ans_yval + 25;
}
}
}
I get the answers in the UI perfectly.
But when I create another inner, outer for loop and try to print the rdbtnanswer object values, values are not there. Each array replaced from last one. I need the reason for that.