Class ApplicationPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ApplicationPanel extends JPanel
The ApplicationPanel class is responsible for rendering the quiz interface and handling the game logic, including:
  • Displaying questions with multiple-choice options.
  • Tracking the player's score.
  • Managing a countdown timer for each question.

This panel uses Swing components to create a GUI-based quiz.

See Also:
  • Field Details

    • timerLabel

      protected JLabel timerLabel
      Label for displaying the countdown timer.
    • questionLabel

      protected JTextArea questionLabel
      Text area for displaying the current question.
    • options

      protected JRadioButton[] options
      Array of radio buttons for the multiple-choice options.
    • group

      protected ButtonGroup group
      Grouping radio buttons to allow only one selection at a time.
    • nextButton

      protected JButton nextButton
      Button for moving to the next question.
    • currentQuestion

      protected int currentQuestion
      Current question index.
    • score

      protected int score
      Player's score.
    • timeLeft

      protected int timeLeft
      Time left in seconds for the current question.
    • timer

      protected Timer timer
      Timer for countdown functionality.
    • optionsPanel

      protected JPanel optionsPanel
      Panel to hold and display the options.
    • questions

      protected String[][] questions
      2D array containing questions, options, and correct answers.
  • Constructor Details

    • ApplicationPanel

      ApplicationPanel()
      Constructs the quiz panel, initializes the GUI layout, and loads the first question.

      Sets up the main layout, timer label, question area, options, and the next button.

  • Method Details

    • loadNextQuestion

      protected void loadNextQuestion()
      Loads the next question into the GUI.

      Updates the question label, sets the options, and starts the timer. If the quiz is over, displays the final score using JOptionPane.

    • startTimer

      protected void startTimer()
      Starts the countdown timer for the current question.

      Decreases the timer by one second every tick. When the timer reaches zero:

      • Automatically checks the answer.
      • Loads the next question.
    • checkAnswer

      protected void checkAnswer()
      Checks the selected answer against the correct answer.

      Increases the score if the answer is correct. Moves to the next question.