Hi I have 2 list defined:
ArrayList<JLabel> questionsList = new ArrayList<JLabel>();
ArrayList<JRadioButton> answersList = new ArrayList<JRadioButton>();
I try to read questions and answers in format like that:
1st Question
answer1
answer2
2nd Question
answer1
answer2
etc.
So 1st question is read from list questionsList then I want to read from another list answersList all answers to that question and etc.
In questionsList I read data from mysql and they are saved in JLabels in format like:
1. Question one
2. Question two
etc
In answersList I read data from mysql and they are saved in JRadioButtons in format like:
answer1
answer2
etc
My code so far:
int height = 0;
for(int i1 =0; i1<questionsList.size(); i1++)
{
client.insideFillPollPanel.add(questionsList.get(i1)).setBounds(20, 20+150*i1, 480, 14);
height = 20+150*i1;
for(int i2 =0; i2<answersList.size(); i2++)
client.insideFillPollPanel.add(answersList.get(i2)).setBounds(20, 50+30*i2, 480, 14);
}
How do i solve it to be display like 1st format I showed so question then asnwers question and asnwers?
I would recommend you to create a
Questionclass which contains both the question and all answers belonging to that question and then, instead of havingYou use
(as a side note: It is considered good practice to program against interfaces, so instead of storing the questions in a
ArrayList<Question>I suggest you go for aList<Question>.)For example: