Skip to content

Commit b65dd3b

Browse files
committed
Simple Quiz Application
This application is in development phase, more feature are still coming.
0 parents  commit b65dd3b

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

  • com.luckytaorem_quiz_application_jar_1.0-SNAPSHOT
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.luckytaorem</groupId>
5+
<artifactId>quiz_application</artifactId>
6+
<version>1.0-SNAPSHOT</version>
7+
<packaging>jar</packaging>
8+
<properties>
9+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
10+
<maven.compiler.source>17</maven.compiler.source>
11+
<maven.compiler.target>17</maven.compiler.target>
12+
</properties>
13+
</project>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.luckytaorem.quiz_application;
7+
import javax.swing.JFrame;
8+
import java.awt.event.ActionListener;
9+
import java.awt.event.ActionEvent;
10+
import javax.swing.ButtonGroup;
11+
import javax.swing.JButton;
12+
import javax.swing.JLabel;
13+
import javax.swing.JOptionPane;
14+
import javax.swing.JRadioButton;
15+
/**
16+
*
17+
* @author Taorem
18+
*/
19+
public class QuizTest extends JFrame implements ActionListener{
20+
21+
JLabel label;
22+
JRadioButton radioButtons[] = new JRadioButton[5];
23+
JButton btnNext,btnResult;
24+
ButtonGroup bg;
25+
int count = 0, current = 0, x=1,y=1,now=0;
26+
int m[]= new int[10];
27+
28+
29+
QuizTest(String s){
30+
super(s);
31+
label = new JLabel();
32+
add(label);
33+
bg = new ButtonGroup();
34+
for(int i=0;i<5;i++){
35+
radioButtons[i]= new JRadioButton();
36+
add(radioButtons[i]);
37+
bg.add(radioButtons[i]);
38+
39+
}
40+
btnNext = new JButton("Next");
41+
btnResult = new JButton("Result");
42+
btnResult.setVisible(false);
43+
btnResult.addActionListener(this);
44+
btnNext.addActionListener(this);
45+
add(btnNext);
46+
add(btnResult);
47+
setData();
48+
label.setBounds(30,40,450,20);
49+
radioButtons[0].setBounds(50,80,450,20);
50+
radioButtons[1].setBounds(50,110,200,20);
51+
radioButtons[2].setBounds(50,140,200,20);
52+
radioButtons[3].setBounds(50,170,200,20);
53+
btnNext.setBounds(100,240,100,30);
54+
btnResult.setBounds(270,240,100,30);
55+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56+
setLayout(null);
57+
setLocation(250,100);
58+
setVisible(true);
59+
setSize(600,350);
60+
}
61+
62+
void setData(){
63+
radioButtons[4].setSelected(true);
64+
if(current==0){
65+
label.setText("Question 1: Correct Radio Button is A");
66+
radioButtons[0].setText("A");
67+
radioButtons[1].setText("B");
68+
radioButtons[2].setText("C");
69+
radioButtons[3].setText("D");
70+
}
71+
if(current==1){
72+
label.setText("Question 2: Correct Radio Button is B");
73+
radioButtons[0].setText("A");
74+
radioButtons[1].setText("B");
75+
radioButtons[2].setText("C");
76+
radioButtons[3].setText("D");
77+
}
78+
label.setBounds(30,40,450,20);
79+
for(int i=0,j=0;i<=90;i+=30,j++){
80+
radioButtons[j].setBounds(50,80+i,200,20);
81+
}
82+
}
83+
84+
boolean checkAns(){
85+
if(current==0){
86+
return(radioButtons[0].isSelected());
87+
}
88+
if(current==1){
89+
return(radioButtons[1].isSelected());
90+
}
91+
return false;
92+
}
93+
94+
public static void main(String[] args){
95+
new QuizTest("Testing for Quiz Application");
96+
}
97+
98+
@Override
99+
public void actionPerformed(ActionEvent e) {
100+
if(e.getSource()==btnNext){
101+
if(checkAns())
102+
count = count +1;
103+
current++;
104+
setData();
105+
if(current==1){
106+
btnNext.setEnabled(false);
107+
btnResult.setVisible(true);
108+
btnResult.setText("Result");
109+
}
110+
}
111+
112+
if(e.getActionCommand().equals("Result")){
113+
if(checkAns())
114+
count = count +1;
115+
current++;
116+
JOptionPane.showMessageDialog(this,"Correct Answer are "+count);
117+
System.exit(0);
118+
}
119+
}
120+
}

0 commit comments

Comments
 (0)