Programming Assignment Unit 1
Programming Assignment Unit 1
1. Swing Components:
• The program uses Swing components (JFrame, JPanel, JLabel, JButton, JRadioButton,
ButtonGroup) to create a graphical user interface (GUI) for the quiz.
3. Correct Answers:
• Correct answers for each question are stored in the correctAnswers array as characters.
4. GUI Initialization:
• The GUI is initialized in the constructor (QuizProgram()) where JFrame, JPanel, JLabels,
JRadioButtons, and JButton are created and configured.
5. Layout Management:
• The layout of the main panel uses a combination of FlowLayout and BoxLayout to organize
components vertically.
• An ActionListener is attached to the "Submit" button to handle button clicks. When clicked,
it calls the checkAnswer method.
7. checkAnswer Method:
• It uses a switch statement to handle user input ('A', 'B', 'C', 'D').
• If the user's answer is correct, the score is incremented. If the input is invalid, an error
message is displayed.
8. getSelectedAnswer Method:
• This method iterates through the radio buttons to determine which one is selected and
returns the corresponding answer.
9. updateQuestion Method:
• This method updates the displayed question and options based on the current question
index.
• This method calculates the percentage of correct answers and displays a message based on
the percentage.
Chrisna Badar
Programming Assignment Unit 1 – Programming 1
• It schedules the creation of the GUI on the event dispatch thread using
SwingUtilities.invokeLater.
• The program uses different fonts and styles to enhance the appearance of the GUI.
Chrisna Badar