Wednesday, 2 August 2017

Exam System project java ~ gniithelp

Online Exam Project in Java Swing without database

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

Output

online exam project in swing output 1 online exam project in swing output 1
credit:- javatpoint

No comments:

Post a Comment