Hello!
I'm attempting to increment the correct answers of radio buttons in Window2.java then I am trying to pass the final value to Window3.java to display it in a JLabel. I have attached the files through zip
Window2.java
In earlier code I have
28. public int countCorrectAnswers;
64. countCorrectAnswers = 0;
//create question 1 and it's radio buttons JLabel question1 = new JLabel("What's the title of the short story?"); JPanel answers1 = new JPanel(); question1Option1 = new JRadioButton("Camping Trip"); question1Option2 = new JRadioButton("Camp Food"); //correct answer question1Option3 = new JRadioButton("Cooking Made Easy"); question1Option4 = new JRadioButton("Food is Great when Camping"); question1Group = new ButtonGroup(); question1Group.add(question1Option1); question1Group.add(question1Option2); question1Group.add(question1Option3); question1Group.add(question1Option4); answers1.add(question1Option1); answers1.add(question1Option2); //correct answer answers1.add(question1Option3); answers1.add(question1Option4); if (question1Option2.isSelected()) countCorrectAnswers++;
The above occurs 5x for 5 questions
Window3.java
public class Window3 extends JFrame { private JLabel results; private JPanel buttonPanel; private JButton button; private JMenuBar menuBar; private JMenu fileMenu; private JMenu aboutMenu; private JMenuItem exitItem; private JMenuItem infoItem; public Window3() { // Set GUI information & layout; display window setTitle("Results of Short Story & Quiz"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); buildMenuBar(); [B]// I want to access countCorrectAnswers from Window2.java in order to display in the following JLabel[/B] JLabel results = new JLabel("You answered " + countCorrectAnswers + " out of 5 correct. That is a ###%."); add(results, BorderLayout.CENTER); buildButtonPanel(); add(button, BorderLayout.SOUTH); pack(); setVisible(true); }