I have this program that reads questions with multiple choice answers from a text file and then displays a random set of them in a JOptionPane (very question in a new Pane). In my text file the questions and the 4 options of answers are all in one line and then I divide them into new lines. Now I want to try to add JRadioButtons before every single answer. Is there someone who can help me. Thank you very much in advance. Here is my code:
Random random = new Random();
for (int i = 0; i < newRanQues; i++) {
int randIndex = random.nextInt(32) + 0;
String randomQuestion = questions.get(randIndex);
randomQuestions.add(randomQuestion);
String different = randomQuestion.replaceAll(";", "\n");
{
JOptionPane.showMessageDialog(null, different, "Question", JOptionPane.INFORMATION_MESSAGE);
JRadioButton answerA = new JRadioButton("A) " + answer[0]);
JRadioButton answerB = new JRadioButton("B) " + answer[1]);
JRadioButton answerC = new JRadioButton("C) " + answer[2]);
JRadioButton answerD = new JRadioButton("D) " + answer[3]);
ButtonGroup group = new ButtonGroup();
group.add(optionA);
group.add(optionB);
group.add(optionC);
group.add(optionD);
return;
}
This should do it: