fork download
  1. Import java.awt.*;
  2. Import java.awt.event.*;
  3. import javax.swing.*;
  4. class Online Test extends JFrame implements Action Listener
  5. {
  6. JLabel l;
  7. JRadioButton jib[]=new JRadioButton[5];
  8. JButton b1,b2;
  9. Button Group bg;
  10. int count=0,current=0,x=1,y=1,now=0;
  11. int m[]=new int[10];
  12. Online Test (String s)
  13. {
  14. super(s);
  15. 38
  16. l=new JLabel ();
  17. add(l);
  18. bg=new ButtonGroup();
  19. for(int i=0;i<5;i++)
  20. {
  21. jb[i]=new JRadioButton();
  22. add(jb[i]);
  23. bg.add (jb[i]);
  24. }
  25. b1=new JButton ("Next");
  26. b2=new JButton ("Bookmark");
  27. b1.addActionListener (this);
  28. b2.addActionListener (this);
  29. add (b1);add(b2);
  30. set();
  31. l.set Bounds(30,40,450,20);
  32. Jb [0]...set Bounds (50, 80, 100, and 20);
  33. Jb [1].set Bounds (50, 110, 100, 20);
  34. Jb [2].set Bounds (50, 140, 100, 20);
  35. Jb [3].set Bounds (50, 170, 100, 20);
  36. B1.set Bounds (100, 240, 100, 30);
  37. 39
  38. B2.set Bounds (270, 240, 100, 30);
  39. SetDefaultCloseOperation (JFrame.E [1].XIT_ON_CLOSE);
  40. Set Layout (null);
  41. Set Location (250,100);
  42. Set Visible (true);
  43. Set Size (600,350);
  44. }
  45. Public void action Performed (Action Event e)
  46. {
  47. If (e.getSource () ==b1)
  48. {
  49. If (check ())
  50. Set ();
  51. If (current==9)
  52. {
  53. b1.setEnabled (false);
  54. b2.setText ("Result");
  55. }
  56. }
  57. 40
  58. If (e.getActionCommand ().equals ("Bookmark"))
  59. {
  60. JButton Bk=new JButton ("Bookmark"+x);
  61. bk.setBounds (480, 20+30*x, 100, 30);
  62. Add (Bk);
  63. bk.addActionListener (this);
  64. m[x]=current;
  65. x++;
  66. set();
  67. if(current==9)
  68. b2.setText ("Result");
  69. set Visible(false);
  70. set Visible(true);
  71. }
  72. for(int i=0,y=1;i<x;i++,y++)
  73. {
  74. if(e.getActionCommand().equals("Bookmark"+y))
  75. {
  76. if(check())
  77. 41
  78. now=current;
  79. current=m[y];
  80. set();
  81. ((JButton)e.getSource()).set Enabled(false);
  82. current=now;
  83. }
  84. }
  85. if(e.getActionCommand().equals("Result"))
  86. {
  87. if(check())
  88. //System.out.println ("correct ans="+count);
  89. JOptionPane.showMessageDialog(this,"correct ans="+count);
  90. System. exit (0);
  91. }
  92. }
  93. Void set()
  94. {
  95. jb[4].setSelected(true);
  96. 42
  97. if(current==0)
  98. {
  99. l.setText("Que1: Which one among these is not a data type");
  100. jb[0].setText("int");jb[1].setText("Float");jb[2].setText("boolean");jb[3].setText("char");
  101. }
  102. if(current==1)
  103. {
  104. l.setText("Que2: Which class is available to all the class automatically");
  105. jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object");jb[3].setText("Act
  106. ionEvent");
  107. }
  108. if(current==2)
  109. {
  110. l.setText ("Que3: Which package is directly available to our class without
  111. importing it");
  112. jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[3].setText("lang");
  113. }
  114. if(current==3)
  115. {
  116. l.setText ("Que4: String class is defined in which package");
  117. 43
  118. jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText("awt")
  119. ;
  120. }
  121. if(current==4)
  122. {
  123. l.setText ("Que5: Which institute is best for java coaching");
  124. jb[0].setText("Utek");jb[1].set Text("Aptech");jb[2].setText("SSS
  125. IT");jb[3].setText("jtek");
  126. }
  127. if(current==5)
  128. {
  129. l.setText("Que6: Which one among these is not a keyword");
  130. jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if");
  131. }
  132. if(current==6)
  133. {
  134. l.setText("Que7: Which one among these is not a class ");
  135. jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent");jb
  136. [3].setText("Button");
  137. }
  138. 44
  139. if(current==7)
  140. {
  141. l.setText("Que8: which one among these is not a function of Object
  142. class");
  143. jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");jb[3].setText("g
  144. etDocumentBase");
  145. }
  146. if(current==8)
  147. {
  148. l.setText ("Que9: which function is not present in Applet class");
  149. jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("destroy");
  150. }
  151. if(current==9)
  152. {
  153. l.setText ("Que10: Which one among these is not a valid component");
  154. jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButtonGroup");jb[3].setTe
  155. xt("JTextArea");
  156. }
  157. l.setBounds (30, 40,450,20);
  158. for (int i=0,j=0;i<=90;i+=30,j++)
  159. 45
  160. jb[j].set Bounds(50,80+i,200,20);
  161. }
  162. Boolean check()
  163. {
  164. if(current==0)
  165. return(jb[1].is Selected());
  166. if(current==1)
  167. return (jb[2].is Selected());
  168. if (current==2)
  169. return(jb[3].is Selected());
  170. if(current==3)
  171. return(jb[0].is Selected());
  172. if(current==4)
  173. return(jb[2].is Selected());
  174. if(current==5)
  175. return(jb[2].is Selected());
  176. if(current==6)
  177. return(jb[1].is Selected());
  178. if(current==7)
  179. return(jb[3].is Selected());
  180. if(current==8)
  181. 46
  182. return(jb[1].is Selected());
  183. if(current==9)
  184. return(jb[2].is Selected());
  185. return false;
  186. }
  187. Public static void main(String s[])
  188. {
  189. New Online Test("Online Test Of Java");
  190. }
  191. }
Success #stdin #stdout 0.02s 25788KB
stdin
Standard input is empty
stdout
Import java.awt.*;
Import java.awt.event.*;
import javax.swing.*;
class Online Test extends JFrame implements Action Listener
{
JLabel l;
JRadioButton jib[]=new JRadioButton[5];
JButton b1,b2;
Button Group bg;
int count=0,current=0,x=1,y=1,now=0;
int m[]=new int[10];
Online Test (String s)
{
super(s);
38
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.set Bounds(30,40,450,20);
Jb [0]...set Bounds (50, 80, 100, and 20);
Jb [1].set Bounds (50, 110, 100, 20);
Jb [2].set Bounds (50, 140, 100, 20);
Jb [3].set Bounds (50, 170, 100, 20);
B1.set Bounds (100, 240, 100, 30);
39
B2.set Bounds (270, 240, 100, 30);
SetDefaultCloseOperation (JFrame.E [1].XIT_ON_CLOSE);
Set Layout (null);
Set Location (250,100);
Set Visible (true);
Set Size (600,350);
}
Public void action Performed (Action Event e)
{
If (e.getSource () ==b1)
{
If (check ())
Count=count+1;
Current++;
Set ();
If (current==9)
{
b1.setEnabled (false);
b2.setText ("Result");
}
}
40
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");
set Visible(false);
set Visible(true);
}
for(int i=0,y=1;i<x;i++,y++)
{
if(e.getActionCommand().equals("Bookmark"+y))
{
if(check())
count=count+1;
41
now=current;
current=m[y];
set();
((JButton)e.getSource()).set Enabled(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);
42
if(current==0)
{
l.setText("Que1: Which one among these is not a data type");
jb[0].setText("int");jb[1].setText("Float");jb[2].setText("boolean");jb[3].setText("char");
}
if(current==1)
{
l.setText("Que2: Which class is available to all the class automatically");
jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object");jb[3].setText("Act
ionEvent");
}
if(current==2)
{
l.setText ("Que3: Which package is directly available to our class without
importing it");
jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[3].setText("lang");
}
if(current==3)
{
l.setText ("Que4: String class is defined in which package");
43
jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText("awt")
;
}
if(current==4)
{
l.setText ("Que5: Which institute is best for java coaching");
jb[0].setText("Utek");jb[1].set Text("Aptech");jb[2].setText("SSS
IT");jb[3].setText("jtek");
}
if(current==5)
{
l.setText("Que6: Which one among these is not a keyword");
jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if");
}
if(current==6)
{
l.setText("Que7: Which one among these is not a class ");
jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent");jb
[3].setText("Button");
}
44
if(current==7)
{
l.setText("Que8: which one among these is not a function of Object
class");
jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");jb[3].setText("g
etDocumentBase");
}
if(current==8)
{
l.setText ("Que9: which function is not present in Applet class");
jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("destroy");
}
if(current==9)
{
l.setText ("Que10: Which one among these is not a valid component");
jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButtonGroup");jb[3].setTe
xt("JTextArea");
}
l.setBounds (30, 40,450,20);
for (int i=0,j=0;i<=90;i+=30,j++)
45
jb[j].set Bounds(50,80+i,200,20);
}
Boolean check()
{
if(current==0)
return(jb[1].is Selected());
if(current==1)
return (jb[2].is Selected());
if (current==2)
return(jb[3].is Selected());
if(current==3)
return(jb[0].is Selected());
if(current==4)
return(jb[2].is Selected());
if(current==5)
return(jb[2].is Selected());
if(current==6)
return(jb[1].is Selected());
if(current==7)
return(jb[3].is Selected());
if(current==8)
46
return(jb[1].is Selected());
if(current==9)
return(jb[2].is Selected());
return false;
}
Public static void main(String s[])
{
New Online Test("Online Test Of Java");
}
}