Online Exam Project in Java Swing without database

Creating an online exam project in Java Swing without a database is possible but it comes with some limitations.

To create an online exam project, you can follow these steps:

  1. Create a new Java project in your IDE.
  2. Create a package named “exam” to store all the classes related to the exam project.
  3. Create a class named “Exam” and extend the JFrame class.
  4. In the Exam class, add all the necessary components such as JLabel, JTextArea, JButton, etc. for the exam interface.
  5. Create a class named “Question” to store the questions and answers of the exam.
  6. In the Question class, add a constructor to initialize the question and its options.
  7. Create an array of Question objects to store all the questions.
  8. Use the random number generator to generate a random number to select a question from the array of questions.
  9. Display the selected question and its options on the exam interface.
  10. Add ActionListener to each button to check the answer of the selected question.

Here’s a sample code for the Exam class:

package exam;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Exam extends JFrame implements ActionListener {

    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    private JLabel lblQuestion;
    private JButton btnOption1;
    private JButton btnOption2;
    private JButton btnOption3;
    private JButton btnOption4;
    private Question[] questions = {
        new Question("What is the capital of France?", "Paris", "Rome", "Madrid", "Berlin"),
        new Question("What is the largest planet in our solar system?", "Jupiter", "Saturn", "Neptune", "Uranus"),
        new Question("What is the largest continent in the world?", "Asia", "Africa", "Europe", "North America"),
        new Question("What is the currency of Japan?", "Yen", "Dollar", "Euro", "Pound"),
        new Question("What is the chemical symbol for gold?", "Au", "Ag", "Fe", "Cu")

    public Exam() {
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();

        lblQuestion = new JLabel("Question");
        lblQuestion.setBounds(10, 11, 414, 14);

        btnOption1 = new JButton("Option 1");
        btnOption1.setBounds(10, 50, 194, 23);

        btnOption2 = new JButton("Option 2");
        btnOption2.setBounds(230, 50, 194, 23);

        btnOption3 = new JButton("Option 3");
        btnOption3.setBounds(10, 95, 194, 23);

        btnOption4 = new JButton("Option 4");
        btnOption4.setBounds(230, 95, 194, 23);


    private void generateQuestion() {
        Random random = new Random();
        int index = random.nextInt(questions.length);
        Question question = questions[index];