Report Javaproject
Report Javaproject
COURSE PROJECT
REPORT ON
ONLINE_JAVA_EXAMINATION
U18IT406
JAVA PROGRAMMING
Submitted to
By
B22IT105
2023-24
CERTIFICATE
This is to certify that MOHAMMED ABBU HUZAIFA bearing Roll No. B22IT105 of IVth Semester
B.Tech Information Technology has successfully completed the course project entitled
1
INDEX
1 ABSTRACT 04
2 PROJECT DESCRIPTION 05
3 CODE IN JAVA 06
4 SCREENSHOTS OF OUTPUT 13
6 CONCLUSION 16
1
ABSTRACT:
1
PROJECT DESCRIPTION
The Java Exam Application is a desktop application developed using Java Swing.
It allows students to register by entering their name and roll number before attempting the exam.
The application presents two exam questions, each in its own frame, with the student's name and
roll number displayed for identification.
Question 1 uses radio buttons for single-choice answers, while Question 2 employs checkboxes for
multiple-choice answers.
Navigation buttons such as 'Next' and 'Previous' facilitate easy traversal between questions.
Upon completing both questions, students can submit their exam using the 'Submit' button.
After submission, a dialog box displays the student's exam details, including their name, roll
number, and answers to both questions.
The application features a visually appealing interface with light blue color applied to main panels
and question labels.
GroupLayout is utilized to organize components within each frame, ensuring proper alignment and
spacing.
Action listeners handle user interactions, such as button clicks and answer submissions.
JOptionPane is used for displaying dialog boxes to provide feedback upon exam submission.
Overall, the Java Exam Application provides an intuitive platform for conducting simple exams on
Java programming concepts, suitable for educational purposes in academic environments
1
CODE IN JAVA
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public JavaExam() {
setTitle("Java Exam");
setSize(500, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
layout.setHorizontalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addComponent(nameLabel)
.addComponent(rollNoLabel))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
1
.addComponent(nameField)
.addComponent(rollNoField)
.addComponent(startButton))
);
layout.setVerticalGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(nameLabel)
.addComponent(nameField))
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(rollNoLabel)
.addComponent(rollNoField))
.addComponent(startButton)
);
add(mainPanel);
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = nameField.getText();
String rollNo = rollNoField.getText();
dispose();
new Question1Frame(name, rollNo);
}
});
setVisible(true);
}
1
class Question1Frame extends JFrame {
private JLabel nameLabel, rollNoLabel, questionLabel;
private JRadioButton[] options;
private JButton nextButton;
private String name, rollNo;
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEA
DING)
.addComponent(nameLabel)
.addComponent(rollNoLabel)
.addComponent(questionLabel)
);
layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(nameLabel)
1
.addComponent(rollNoLabel)
.addComponent(questionLabel)
);
panelLayout.setHorizontalGroup(panelLayout.createParallelGroup(GroupLayout.Alig
nment.LEADING)
.addComponent(mainPanel)
.addComponent(optionsPanel)
.addComponent(buttonPanel)
);
panelLayout.setVerticalGroup(panelLayout.createSequentialGroup()
.addComponent(mainPanel)
.addComponent(optionsPanel)
1
.addComponent(buttonPanel)
);
nextButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String answer = "";
for (JRadioButton option : options) {
if (option.isSelected()) {
answer = option.getText().substring(0, 1);
break;
}
}
dispose();
new Question2Frame(name, rollNo, answer);
}
});
setVisible(true);
}
}
private static final String QUESTION = "Which of the following are access modifiers in
Java? (Select multiple)";
private static final String[] OPTIONS = {"A. public", "B. private", "C. protected", "D.
static"};
1
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEA
DING)
.addComponent(nameLabel)
.addComponent(rollNoLabel)
.addComponent(questionLabel)
);
layout.setVerticalGroup(layout.createSequentialGroup()
.addComponent(nameLabel)
.addComponent(rollNoLabel)
.addComponent(questionLabel)
);
1
buttonPanel.setBackground(new Color(173, 216, 230)); // Light blue color
buttonPanel.setLayout(new FlowLayout());
panelLayout.setHorizontalGroup(panelLayout.createParallelGroup(GroupLayout.Alig
nment.LEADING)
.addComponent(mainPanel)
.addComponent(optionsPanel)
.addComponent(buttonPanel)
);
panelLayout.setVerticalGroup(panelLayout.createSequentialGroup()
.addComponent(mainPanel)
.addComponent(optionsPanel)
.addComponent(buttonPanel)
);
prevButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
new Question1Frame(name, rollNo);
}
});
submitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
StringBuilder result = new StringBuilder("Exam submitted for: ");
result.append(name).append(" (Roll No: ").append(rollNo).append(")\n\n");
1
result.append("Question 1: ").append(prevAnswer).append("\n");
result.append("Question 2: ");
StringBuilder answers = new StringBuilder();
for (int i = 0; i < options.length; i++) {
if (options[i].isSelected()) {
answers.append(OPTIONS[i].charAt(0)).append(", ");
}
}
if (answers.length() > 0) {
answers.deleteCharAt(answers.length() - 2); // Remove the last comma and
space
}
result.append(answers);
setVisible(true);
}
}
SCREENSHOTS OF OUTPUT
1
Fig no : 2 - Question-1
1
Fig no: 4 : submission
1. As a student, after completing this project, I am able to design real time application.
1
CONCLUSION
1
1