java - JRadioButtons before every line -


i have program reads questions multiple choice answers text file , displays random set of them in joptionpane (very question in new pane). in text file questions , 4 options of answers in 1 line , divide them new lines. want try add jradiobuttons before every single answer. there can me. thank in advance. here code:

random random = new random();         (int = 0; < 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 it:

import java.awt.borderlayout; import java.awt.gridbagconstraints; import java.awt.gridbaglayout;  import javax.swing.buttongroup; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; import javax.swing.jradiobutton;  public class radiobuttonexample {      public static void main(string[] args) {         init();     }      private static void init() {         // create jframe         jframe jframe = new jframe("question");         // create answers         string[] answer = { "red", "green", "yellow", "blue, no, red, no... arrrrrg" };         // create radio buttons         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]);         // create button group         buttongroup group = new buttongroup();         group.add(answera);         group.add(answerb);         group.add(answerc);         group.add(answerd);         // add question jframe         jframe.add(new jlabel("what favorite colour?"), borderlayout.north);         // create gridbag layout , constraints         gridbaglayout gbl = new gridbaglayout();         // create panel using gbl         jpanel pan = new jpanel(gbl);         // create constraints         gridbagconstraints cons = new gridbagconstraints();         cons.gridwidth = 1;         cons.fill = gridbagconstraints.horizontal;         // answer 1         cons.gridx = 0;         cons.gridy = 1;         pan.add(answera, cons);         // answer 1         cons.gridx = 0;         cons.gridy = 2;         pan.add(answerb, cons);         // answer 1         cons.gridx = 0;         cons.gridy = 3;         pan.add(answerc, cons);         // answer 1         cons.gridx = 0;         cons.gridy = 4;         pan.add(answerd, cons);         // add panel jframe         jframe.add(pan, borderlayout.center);         // show jframe         jframe.setsize(400, 400);         jframe.setvisible(true);     } } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -