-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnlineTest.java
184 lines (181 loc) · 5.03 KB
/
OnlineTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*Online Java Paper Test*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class OnlineTest extends JFrame implements ActionListener
{
JLabel l;
JRadioButton jb[]=new JRadioButton[5];
JButton b1,b2;
ButtonGroup bg;
int count=0,current=0,x=1,y=1,now=0;
int m[]=new int[10];
OnlineTest(String s)
{
super(s);
l=new JLabel();
add(l);
bg=new ButtonGroup();
for(int i=0;i<5;i++)
{
jb[i]=new JRadioButton();
add(jb[i]);
bg.add(jb[i]);
}
b1=new JButton("Next");
b2=new JButton("Bookmark");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);
set();
l.setBounds(30,40,450,20);
jb[0].setBounds(50,80,100,20);
jb[1].setBounds(50,110,100,20);
jb[2].setBounds(50,140,100,20);
jb[3].setBounds(50,170,100,20);
b1.setBounds(100,240,100,30);
b2.setBounds(270,240,100,30);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setLocation(250,100);
setVisible(true);
setSize(600,350);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
if(check())
count=count+1;
current++;
set();
if(current==9)
{
b1.setEnabled(false);
b2.setText("Result");
}
}
if(e.getActionCommand().equals("Bookmark"))
{
JButton bk=new JButton("Bookmark"+x);
bk.setBounds(480,20+30*x,100,30);
add(bk);
bk.addActionListener(this);
m[x]=current;
x++;
current++;
set();
if(current==9)
b2.setText("Result");
setVisible(false);
setVisible(true);
}
for(int i=0,y=1;i<x;i++,y++)
{
if(e.getActionCommand().equals("Bookmark"+y))
{
if(check())
count=count+1;
now=current;
current=m[y];
set();
((JButton)e.getSource()).setEnabled(false);
current=now;
}
}
if(e.getActionCommand().equals("Result"))
{
if(check())
count=count+1;
current++;
//System.out.println("correct ans="+count);
JOptionPane.showMessageDialog(this,"correct ans="+count);
System.exit(0);
}
}
void set()
{
jb[4].setSelected(true);
if(current==0)
{
l.setText("Que1: On which date Queen Elizabeth died?");
jb[0].setText("8 August 2022");jb[1].setText("8 September 2022");jb[2].setText("9 September 2022");jb[3].setText("9 August 2022");
}
if(current==1)
{
l.setText("Que2: Who is the president of India?");
jb[0].setText("Rahul Gandhi");jb[1].setText("Narendra Modi");jb[2].setText("Droupadi Murmu");jb[3].setText("RamNath Kovind");
}
if(current==2)
{
l.setText("Que3: Who is the owner of TATA Industries?");
jb[0].setText("Dirubhai Ambani");jb[1].setText("Gautam Adani");jb[2].setText("Elon Musk");jb[3].setText("Ratan Tata");
}
if(current==3)
{
l.setText("Que4: What is the full form of NATO?");
jb[0].setText("North Atlantic Treaty Organization");jb[1].setText("North And Top Organization");jb[2].setText("Nepal Afghanistan Turkey Organised");jb[3].setText("New Armed Terror Organisation");
}
if(current==4)
{
l.setText("Que5: Which among the following is not an Union Territory of India?");
jb[0].setText("Ladakh");jb[1].setText("Chandigarh");jb[2].setText("Chennai");jb[3].setText("Delhi");
}
if(current==5)
{
l.setText("Que6: Who is known as Iron man of India?");
jb[0].setText("Robert Downey Junior");jb[1].setText("APJ Abdul Kalam");jb[2].setText("Vallabhbhai Patel");jb[3].setText("Siddharth Mehrotra");
}
if(current==6)
{
l.setText("Que7: Who discoverd 0 first?");
jb[0].setText("Srinivasa Ramanujan");jb[1].setText("Aryabhatta");jb[2].setText("Brahmagupta");jb[3].setText("C.V. Raman");
}
if(current==7)
{
l.setText("Que8: Bill Gates founded which software company?");
jb[0].setText("Tesla");jb[1].setText("Adobe");jb[2].setText("Google");jb[3].setText("Microsoft");
}
if(current==8)
{
l.setText("Que9: Andrew Garfield played spiderman role of which of the following movie?");
jb[0].setText("Spiderman: Far from Home");jb[1].setText("Amazing Spiderman");jb[2].setText("Spider-Man");jb[3].setText("The Amazing Spoiderman");
}
if(current==9)
{
l.setText("Que10: Which Pokemon does Ash always carry in Pokemon comic?");
jb[0].setText("Mewtoo");jb[1].setText("Onix");jb[2].setText("Pikachu");jb[3].setText("Chikorita");
}
l.setBounds(30,40,450,20);
for(int i=0,j=0;i<=90;i+=30,j++)
jb[j].setBounds(50,80+i,200,20);
}
boolean check()
{
if(current==0)
return(jb[1].isSelected());
if(current==1)
return(jb[2].isSelected());
if(current==2)
return(jb[3].isSelected());
if(current==3)
return(jb[0].isSelected());
if(current==4)
return(jb[2].isSelected());
if(current==5)
return(jb[2].isSelected());
if(current==6)
return(jb[1].isSelected());
if(current==7)
return(jb[3].isSelected());
if(current==8)
return(jb[1].isSelected());
if(current==9)
return(jb[2].isSelected());
return false;
}
public static void main(String s[])
{
new OnlineTest("Online Test Of Java by Nilanjan");
}
}