Skip to content

Commit d4ddad1

Browse files
Online Exam Project Using Java
Useful for conducting online exams
1 parent 53d787c commit d4ddad1

File tree

1 file changed

+186
-0
lines changed

1 file changed

+186
-0
lines changed

Online Exam Using Java

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
2+
import java.awt.*;
3+
import java.awt.event.*;
4+
import javax.swing.*;
5+
6+
class OnlineTest extends JFrame implements ActionListener
7+
{
8+
JLabel l;
9+
JRadioButton jb[]=new JRadioButton[5];
10+
JButton b1,b2;
11+
ButtonGroup bg;
12+
int count=0,current=0,x=1,y=1,now=0;
13+
int m[]=new int[10];
14+
OnlineTest(String s)
15+
{
16+
super(s);
17+
l=new JLabel();
18+
add(l);
19+
bg=new ButtonGroup();
20+
for(int i=0;i<5;i++)
21+
{
22+
jb[i]=new JRadioButton();
23+
add(jb[i]);
24+
bg.add(jb[i]);
25+
}
26+
b1=new JButton("Next");
27+
b2=new JButton("Bookmark");
28+
b1.addActionListener(this);
29+
b2.addActionListener(this);
30+
add(b1);add(b2);
31+
set();
32+
l.setBounds(30,40,450,20);
33+
jb[0].setBounds(50,80,100,20);
34+
jb[1].setBounds(50,110,100,20);
35+
jb[2].setBounds(50,140,100,20);
36+
jb[3].setBounds(50,170,100,20);
37+
b1.setBounds(100,240,100,30);
38+
b2.setBounds(270,240,100,30);
39+
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
40+
setLayout(null);
41+
setLocation(250,100);
42+
setVisible(true);
43+
setSize(600,350);
44+
}
45+
public void actionPerformed(ActionEvent e)
46+
{
47+
if(e.getSource()==b1)
48+
{
49+
if(check())
50+
count=count+1;
51+
current++;
52+
set();
53+
if(current==9)
54+
{
55+
b1.setEnabled(false);
56+
b2.setText("Result");
57+
}
58+
}
59+
if(e.getActionCommand().equals("Bookmark"))
60+
{
61+
JButton bk=new JButton("Bookmark"+x);
62+
bk.setBounds(480,20+30*x,100,30);
63+
add(bk);
64+
bk.addActionListener(this);
65+
m[x]=current;
66+
x++;
67+
current++;
68+
set();
69+
if(current==9)
70+
b2.setText("Result");
71+
setVisible(false);
72+
setVisible(true);
73+
}
74+
for(int i=0,y=1;i<x;i++,y++)
75+
{
76+
if(e.getActionCommand().equals("Bookmark"+y))
77+
{
78+
if(check())
79+
count=count+1;
80+
now=current;
81+
current=m[y];
82+
set();
83+
((JButton)e.getSource()).setEnabled(false);
84+
current=now;
85+
}
86+
}
87+
88+
if(e.getActionCommand().equals("Result"))
89+
{
90+
if(check())
91+
count=count+1;
92+
current++;
93+
//System.out.println("correct ans="+count);
94+
JOptionPane.showMessageDialog(this,"correct ans="+count);
95+
System.exit(0);
96+
}
97+
}
98+
void set()
99+
{
100+
jb[4].setSelected(true);
101+
if(current==0)
102+
{
103+
l.setText("Que1: Which one among these is not a primitive datatype?");
104+
jb[0].setText("int");jb[1].setText("Float");jb[2].setText("boolean");jb[3].setText("char");
105+
}
106+
if(current==1)
107+
{
108+
l.setText("Que2: Which class is available to all the class automatically?");
109+
jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object");jb[3].setText("ActionEvent");
110+
}
111+
if(current==2)
112+
{
113+
l.setText("Que3: Which package is directly available to our class without importing it?");
114+
jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[3].setText("lang");
115+
}
116+
if(current==3)
117+
{
118+
l.setText("Que4: String class is defined in which package?");
119+
jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText("awt");
120+
}
121+
if(current==4)
122+
{
123+
l.setText("Que5: Which institute is best for java coaching?");
124+
jb[0].setText("Utek");jb[1].setText("Aptech");jb[2].setText("SSS IT");jb[3].setText("jtek");
125+
}
126+
if(current==5)
127+
{
128+
l.setText("Que6: Which one among these is not a keyword?");
129+
jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if");
130+
}
131+
if(current==6)
132+
{
133+
l.setText("Que7: Which one among these is not a class? ");
134+
jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent");
135+
jb[3].setText("Button");
136+
}
137+
if(current==7)
138+
{
139+
l.setText("Que8: which one among these is not a function of Object class?");
140+
jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");
141+
jb[3].setText("getDocumentBase");
142+
}
143+
if(current==8)
144+
{
145+
l.setText("Que9: which function is not present in Applet class?");
146+
jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("destroy");
147+
}
148+
if(current==9)
149+
{
150+
l.setText("Que10: Which one among these is not a valid component?");
151+
jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButtonGroup");
152+
jb[3].setText("JTextArea");
153+
}
154+
l.setBounds(30,40,450,20);
155+
for(int i=0,j=0;i<=90;i+=30,j++)
156+
jb[j].setBounds(50,80+i,200,20);
157+
}
158+
boolean check()
159+
{
160+
if(current==0)
161+
return(jb[1].isSelected());
162+
if(current==1)
163+
return(jb[2].isSelected());
164+
if(current==2)
165+
return(jb[3].isSelected());
166+
if(current==3)
167+
return(jb[0].isSelected());
168+
if(current==4)
169+
return(jb[2].isSelected());
170+
if(current==5)
171+
return(jb[2].isSelected());
172+
if(current==6)
173+
return(jb[1].isSelected());
174+
if(current==7)
175+
return(jb[3].isSelected());
176+
if(current==8)
177+
return(jb[1].isSelected());
178+
if(current==9)
179+
return(jb[2].isSelected());
180+
return false;
181+
}
182+
public static void main(String s[])
183+
{
184+
new OnlineTest("Online Test Of Java");
185+
}
186+
}

0 commit comments

Comments
 (0)