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 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 ()) Current++; Set (); { 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); x++; Current++; set(); 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()) 41 set(); ((JButton)e.getSource()).set Enabled(false); } } if(e.getActionCommand().equals("Result")) { if(check()) Current++; //System.out.println ("correct ans="+count); } } Void set() { jb[4].setSelected(true); 42 { 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"); } { 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"); } { 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"); } { 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") ; } { 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"); } { 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"); } { 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 { 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"); } { 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"); } { 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() { return(jb[1].is Selected()); return (jb[2].is Selected()); return(jb[3].is Selected()); return(jb[0].is Selected()); return(jb[2].is Selected()); return(jb[2].is Selected()); return(jb[1].is Selected()); return(jb[3].is Selected()); 46 return(jb[1].is Selected()); return(jb[2].is Selected()); return false; } Public static void main(String s[]) { New Online Test("Online Test Of Java"); } }
Standard input is empty
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"); } }