Java Project Code On Online Quiz: SUBMITTED TO - Mrs. Sonal Gehlot
Java Project Code On Online Quiz: SUBMITTED TO - Mrs. Sonal Gehlot
ONLINE QUIZ
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class login
{ login(String str) {
JFrame f=new JFrame("Password Field");
Font font1=new Font("Bauhaus 93",Font.BOLD,28);
Font font2=new Font("Bauhaus 93",Font.BOLD,28);
Font font3=new Font("Aerial",Font.BOLD,14);
JPasswordField value=new JPasswordField();
value.setBounds(600,200,100,30);
JLabel text=new JLabel("*****WELCOME TO THE ONLINE GK QUIZ******");
text.setBounds(300,20,10000,30);
text.setFont(font1);
JLabel l=new JLabel("LOGIN HERE");
l.setBounds(525,80,200,50);
l.setFont(font2);
JLabel username=new JLabel("USERNAME");
username.setBounds(500,133,160,60);
username.setFont(font3);
JLabel password=new JLabel("PASSWORD");
password.setBounds(500,183,160,60);
password.setFont(font3);
JButton b=new JButton("LOGIN");
b.setBounds(550,250,80,30);
JTextField jtf=new JTextField();
jtf.setBounds(600,150,100,30);
f.add(value);
f.add(text);
f.add(username);
f.add(l);
f.add(password);
f.add(b);
f.add(jtf);
f.setSize(1250,450);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
String name=jtf.getText();
String psd=String.valueOf(value.getPassword());
if(name.equals("16csu267")&&psd.equals("ncu"))
{
JOptionPane.showMessageDialog(jtf,"LOGGED IN SUCCESSFULLY");
new Instructions();
}
else
{
JOptionPane.showMessageDialog(jtf,"EITHER THE USERNAME OR PASSWORD IS
WRONG! TRY AGAIN");
}
}
});
}
}
#3 INSTRUCTIONS CODE
package abcd;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
jf.setSize(1500,650);
jf.setLayout(null);
jf.setVisible(true);
b.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b)
{
new OnlineExam("ONLINE QUIZ");
}
}
});
}
import java.awt.event.*;
import javax.swing.*;
class OnlineExam extends JFrame implements ActionListener
{ private static final long serialVersionUID = 1L;
JRadioButton jrb[]=new JRadioButton[5];
JLabel lb;
JButton b1,b2;
ButtonGroup bg;
int ctrright=0,ctrwrong=0,currentques=0,x=1,y=1,now=0;
int totalques[]=new int[10];
OnlineExam(String str)
{ super(str);
lb=new JLabel();
add(lb);
bg=new ButtonGroup();
for(int i=0;i<5;i++)
{ jrb[i]=new JRadioButton();
add(jrb[i]);
bg.add(jrb[i]);
}
b1=new JButton("SAVE AND NEXT");
b2=new JButton("MARK FOR REVIEW");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);
add(b2);
SetQuestions();
lb.setBounds(30,40,450,20);
jrb[0].setBounds(50,80,1000,20);
jrb[1].setBounds(50,110,1000,20);
jrb[2].setBounds(50,140,1000,20);
jrb[3].setBounds(50,170,1000,20);
b1.setBounds(100,240,130,30);
b2.setBounds(300,240,150,30);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setLocation(250,100);
setVisible(true);
setSize(825,350);
}
void SetQuestions()
{ jrb[4].setSelected(true);
if(currentques==0)
{
lb.setText("#Q1 Considering facts about Sun, mean average distance of Sun from Earth is");
jrb[0].setText("150 million Km");
jrb[1].setText("200 million Km");
jrb[2].setText("250 million Km");
jrb[3].setText("300 million Km");
}
if(currentques==1)
{
lb.setText("#Q2 Second closest dwarf planet to Sun is");
jrb[0].setText("Eris");
jrb[1].setText("Pluto");
jrb[2].setText("Saturn");
jrb[3].setText("Ceres");
}
if(currentques==2)
{
lb.setText("#Q3 Considering facts about Uranus, number of known artificial satellites 'Moon'
are");
jrb[0].setText("35");
jrb[1].setText("32");
jrb[2].setText("27");
jrb[3].setText("25");
}
if(currentques==3)
{
lb.setText("#Q4 Name of most massive dwarf planet is");
jrb[0].setText("Saturn");
jrb[1].setText("Ceres");
jrb[2].setText("Eres");
jrb[3].setText("Pluto");
}
if(currentques==4)
{
lb.setText("#Q5 In December solstice, sun shines indirectly on");
jrb[0].setText("northern hemisphere");
jrb[1].setText("southern hemisphere");
jrb[2].setText("eastern hemisphere");
jrb[3].setText("western hemisphere");
}
if(currentques==5)
{
lb.setText("#Q6 First man made craft Venera 3 was launched in");
jrb[0].setText("1966");
jrb[1].setText("1986");
jrb[2].setText("1981");
jrb[3].setText("1991");
}
if(currentques==6)
{
lb.setText("#Q7 Smallest planet in Solar System which is closest to Sun is ");
jrb[0].setText("Earth");
jrb[1].setText("Mercury");
jrb[2].setText("Venus");
jrb[3].setText("Mars");
}
if(currentques==7)
{
lb.setText("#Q8 Diameter of Earth's natural satellite Moon is");
jrb[0].setText("3575 KM");
jrb[1].setText("3475 KM");
jrb[2].setText("4475 KM");
jrb[3].setText("5575 KM");
}
if(currentques==8)
{
lb.setText("#Q9 Considering facts about Mars, orbit distance of planet Mars in terms of
Astronomical Units is");
jrb[0].setText("1.38");
jrb[1].setText("1.58");
jrb[2].setText("1.48");
jrb[3].setText("1.68");
}
if(currentques==9)
{
lb.setText("#Q10 Orbit of planet Venus around Sun is completed in");
jrb[0].setText("230 Earth days");
jrb[1].setText("225 Earth days");
jrb[2].setText("265 Earth days");
jrb[3].setText("285 Earth days");
}
lb.setBounds(30,40,450,20);
for(int i=0,j=0;i<=90;i+=30,j++)
jrb[j].setBounds(50,80+i,200,20);
}
boolean CheckQues()
{
if(currentques==0)
return(jrb[1].isSelected());
if(currentques==1)
return(jrb[2].isSelected());
if(currentques==2)
return(jrb[4].isSelected());
if(currentques==3)
return(jrb[3].isSelected());
if(currentques==4)
return(jrb[1].isSelected());
if(currentques==5)
return(jrb[1].isSelected());
if(currentques==6)
return(jrb[2].isSelected());
if(currentques==7)
return(jrb[2].isSelected());
if(currentques==8)
return(jrb[1].isSelected());
if(currentques==9)
return(jrb[2].isSelected());
return false;
}
}