Online Exam Project in Java Swing without database

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

Output

online exam project in swing output 1 online exam project in swing output 1

Next TopicJava Layout Manager
java for beginners
java for beginners
java for beginners
CodSir //course // books
...

WikiSir

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 […]

Tags:

....
...