Example #1
0
 // Resets the game
 public void reset() {
   panel.remove(btnext);
   panel.add(choice1);
   panel.add(choice2);
   panel.add(choice3);
   panel.add(choice4);
   panel.add(btnext);
   quizAnswerID = 0;
   map.clear();
   readQuestionAnswer(quizAnswerID);
   btnext.setText("Next");
 }
Example #2
0
 // Set up the quiz window
 Quiz() {
   initializeData();
   setTitle("FOSS Quiz App");
   setDefaultCloseOperation(EXIT_ON_CLOSE);
   setSize(440, 400);
   setLocation(300, 100);
   setResizable(true);
   Container cont = getContentPane();
   cont.setLayout(null);
   cont.setBackground(Color.WHITE);
   bg = new ButtonGroup();
   choice1 = new JRadioButton("Choice1", true);
   choice2 = new JRadioButton("Choice2", false);
   choice3 = new JRadioButton("Choice3", false);
   choice4 = new JRadioButton("Choice4", false);
   bg.add(choice1);
   bg.add(choice2);
   bg.add(choice3);
   bg.add(choice4);
   lblmess = new JLabel("Choose a correct anwswer");
   lblmess.setForeground(Color.BLACK);
   lblmess.setFont(new Font("Sans_Serif", Font.BOLD, 15));
   btnext = new JButton("Next");
   btnext.setForeground(Color.WHITE);
   btnext.setFont(new Font("Sans_Serif", Font.BOLD, 17));
   btnext.setBackground(Color.DARK_GRAY);
   btnext.addActionListener(this);
   panel = new JPanel();
   panel.setBackground(Color.WHITE);
   panel.setLocation(10, 60);
   panel.setSize(400, 300);
   panel.setLayout(new GridLayout(0, 1));
   title = new JPanel();
   title.setBackground(Color.WHITE);
   title.setLocation(10, 10);
   title.setSize(1000, 50);
   title.setLayout(new GridLayout(1, 0));
   title.add(lblmess);
   panel.add(choice1);
   panel.add(choice2);
   panel.add(choice3);
   panel.add(choice4);
   panel.add(btnext);
   cont.add(title);
   cont.add(panel);
   setVisible(true);
   quizAnswerID = 0;
   readQuestionAnswer(quizAnswerID);
 }
Example #3
0
 // Handle button clicks, specifically the next button
 public void actionPerformed(ActionEvent e) {
   if (btnext.getText().equals("Next")) {
     if (quizAnswerID < 9) {
       map.put(quizAnswerID, getSelection());
       quizAnswerID++;
       readQuestionAnswer(quizAnswerID);
     } else {
       map.put(quizAnswerID, getSelection());
       btnext.setText("Show results");
     }
   } else if (btnext.getText().equals("Show results")) {
     blankScreen();
   } else if (btnext.getText().equals("Try again")) {
     reset();
   }
 }