PROJECT- QUIZ APLLICTION USING JAVA AND Apache NetBeans
Login. Java
package [Link];//name of package
import [Link].*;
import [Link].*;
import [Link].*;
public class Login extends JFrame implements ActionListener{
JButton rules,back; //globally defined
JTextField tfname;
Login(){
getContentPane().setBackground([Link]);
setLayout(null);//It helps to set layout by your own
ImageIcon i1 = new ImageIcon([Link]("icons/[Link]"));
JLabel image = new JLabel(i1);
[Link](0, 0, 600, 500);
add(image);
JLabel heading = new JLabel("Simple Minds");
[Link](750, 60, 300,45);
[Link](new Font("Viner Hand ITC", [Link],40));
[Link](new Color(30,144,254));//For color of heading
add(heading);
JLabel name = new JLabel("Enter Your name");
[Link](810,150, 300, 20);
[Link](new Font("Mongolian Baiti", [Link],18));
[Link](new Color(30,144,254));//For color of heading
add(name);
//For creating Box to write text
tfname = new JTextField();
[Link](735,200,300,25);
[Link](new Font("Times New Roman", [Link],20));
add(tfname);
//To create Button we Jbutton class
rules = new JButton("Rules");
[Link](735, 270, 120, 25);
[Link](new Color(30, 144, 254));//for color
[Link]([Link]);
[Link](this);//some action performed on buttons
add(rules);
//To create Button we Jbutton class
back = new JButton("Back");
[Link](915, 270, 120, 25);
[Link](new Color(30, 144, 254));//for color
[Link]([Link]);
[Link](this);
add(back);
//size of frame
setSize(1200,500); //width and height of frame
setLocation(200,150);
setVisible(true);// to show Frame
}
public void actionPerformed(ActionEvent ae){
if([Link]() == rules){
/*with the help of get text what ever the value is entered by user we acn find ut that*/
String name = [Link]();
setVisible(false);//helps to new application
new Rules(name);
} else if ([Link]() == back){
setVisible(false);//this helps to close the button
}
}
public static void main(String[] args){
new Login();
}
}
OUTPUT
Rules. Java
package [Link];
import [Link].*;
import [Link].*;//This import color class
import [Link].*;
public class Rules extends JFrame implements ActionListener{
String name;
JButton start, back;
Rules(String name) {
[Link] = name;
getContentPane().setBackground([Link]);//color of frame
setLayout(null);
JLabel heading = new JLabel("Welcome " + name + " to Simple Minds");
[Link](50, 20, 700,30);
[Link](new Font("Viner Hand ITC", [Link],28));
[Link](new Color(30,144,254));//For color of heading
add(heading);
JLabel rules = new JLabel();
[Link](20, 90, 700,350);
[Link](new Font("Tahoma", [Link],16));
[Link](
"<html>"+
"1. You are trained to be a programmer and not a story teller, answer point to
point" + "<br><br>" +
"2. Do not unnecessarily smile at the person sitting next to you, they may also not
know the answer" + "<br><br>" +
"3. You may have lot of options in life but here all the questions are compulsory" +
"<br><br>" +
"4. Crying is allowed but please do so quietly." + "<br><br>" +
"5. Only a fool asks and a wise answers (Be wise, not otherwise)" + "<br><br>" +
"6. Do not get nervous if your friend is answering more questions, may be he/she is
doing Jai Mata Di" + "<br><br>" +
"7. Brace yourself, this paper is not for the faint hearted" + "<br><br>" +
"8. May you know more than what John Snow knows, Good Luck" + "<br><br>"
+//br is for break row
"<html>"
);
add(rules);
//To create Button we Jbutton class
back = new JButton("Back");
[Link](250, 500, 100, 30);
[Link](new Color(30, 144, 254));//for color
[Link]([Link]);
[Link](this);
add(back);
//To create Button we Jbutton class
start = new JButton("Start");
[Link](400, 500, 100, 30);
[Link](new Color(30, 144, 254));//for color
[Link]([Link]);
[Link](this);//some action performed on buttons
add( start);
//this creats a frame
setSize(800, 650);
setLocation(350, 100);
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if ([Link]() == start){
setVisible(false);
new Quiz(name);
}else{
setVisible(false);//to close current frame
new Login();
}
}
public static void main(String[] args){
new Rules("User");
}
}
OUTPUT
Quiz. Java
package [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
public class Quiz extends JFrame implements ActionListener{
String questions[][] = new String[10][5];
String answers[][] = new String[10][2];
String useranswers[][] = new String[10][1];
JLabel qno, question;
JRadioButton opt1, opt2, opt3, opt4;
ButtonGroup groupoptions;
JButton next, submit, lifeline;
public static int timer = 15;
public static int ans_given = 0;//flag
public static int count = 0;
public static int score = 0;
String name;
Quiz(String name){
[Link] = name;
setBounds(40, 0, 1200, 650);
getContentPane().setBackground([Link]);
setLayout(null);
ImageIcon i1 = new ImageIcon([Link]("icons/[Link]"));
JLabel image = new JLabel(i1);
[Link](0, 0, 1200, 300);
add(image);
qno = new JLabel();
[Link](100, 350, 50, 30);
[Link](new Font("Tahoma", [Link], 24));
add(qno);
question = new JLabel();
[Link](150, 350, 900, 30);
[Link](new Font("Tahoma", [Link], 24));
add(question);
questions[0][0] = "Which is used to find and fix bugs in the Java programs.?";
questions[0][1] = "JVM";
questions[0][2] = "JDB";
questions[0][3] = "JDK";
questions[0][4] = "JRE";
questions[1][0] = "What is the return type of the hashCode() method in the Object
class?";
questions[1][1] = "int";
questions[1][2] = "Object";
questions[1][3] = "long";
questions[1][4] = "void";
questions[2][0] = "Which package contains the Random class?";
questions[2][1] = "[Link] package";
questions[2][2] = "[Link] package";
questions[2][3] = "[Link] package";
questions[2][4] = "[Link] package";
questions[3][0] = "An interface with no fields or methods is known as?";
questions[3][1] = "Runnable Interface";
questions[3][2] = "Abstract Interface";
questions[3][3] = "Marker Interface";
questions[3][4] = "CharSequence Interface";
questions[4][0] = "In which memory a String is stored, when we create a string using
new operator?";
questions[4][1] = "Stack";
questions[4][2] = "String memory";
questions[4][3] = "Random storage space";
questions[4][4] = "Heap memory";
questions[5][0] = "Which of the following is a marker interface?";
questions[5][1] = "Runnable interface";
questions[5][2] = "Remote interface";
questions[5][3] = "Readable interface";
questions[5][4] = "Result interface";
questions[6][0] = "Which keyword is used for accessing the features of a package?";
questions[6][1] = "import";
questions[6][2] = "package";
questions[6][3] = "extends";
questions[6][4] = "export";
questions[7][0] = "In java, jar stands for?";
questions[7][1] = "Java Archive Runner";
questions[7][2] = "Java Archive";
questions[7][3] = "Java Application Resource";
questions[7][4] = "Java Application Runner";
questions[8][0] = "Which of the following is a mutable class in java?";
questions[8][1] = "[Link]";
questions[8][2] = "[Link]";
questions[8][3] = "[Link]";
questions[8][4] = "[Link]";
questions[9][0] = "Which of the following option leads to the portability and security of
Java?";
questions[9][1] = "Bytecode is executed by JVM";
questions[9][2] = "The applet makes the Java code secure and portable";
questions[9][3] = "Use of exception handling";
questions[9][4] = "Dynamic binding between objects";
answers[0][1] = "JDB";
answers[1][1] = "int";
answers[2][1] = "[Link] package";
answers[3][1] = "Marker Interface";
answers[4][1] = "Heap memory";
answers[5][1] = "Remote interface";
answers[6][1] = "import";
answers[7][1] = "Java Archive";
answers[8][1] = "[Link]";
answers[9][1] = "Bytecode is executed by JVM";
opt1 = new JRadioButton();
[Link](170, 400, 700, 30);
[Link]([Link]);
[Link](new Font("Dialog", [Link],20));
add(opt1);
opt2 = new JRadioButton();
[Link](170, 440, 700, 30);
[Link]([Link]);
[Link](new Font("Dialog", [Link],20));
add(opt2);
opt3 = new JRadioButton();
[Link](170, 480, 700, 30);
[Link]([Link]);
[Link](new Font("Dialog", [Link],20));
add(opt3);
opt4 = new JRadioButton();
[Link](170, 520, 700, 30);
[Link]([Link]);
[Link](new Font("Dialog", [Link],20));
add(opt4);
groupoptions = new ButtonGroup();
[Link](opt1);
[Link](opt2);
[Link](opt3);
[Link](opt4);
//This is for next button
next = new JButton("Next");
[Link](900, 400, 200, 40);
[Link](new Font("Tahoma", [Link], 22));
[Link](new Color(30, 144, 255));
[Link]([Link]);
[Link](this);
add(next);
//This is for next button
lifeline = new JButton("50-50 Lifeline");
[Link](900, 450, 200, 40);
[Link](new Font("Tahoma", [Link], 22));
[Link](new Color(30, 144, 255));
[Link]([Link]);
[Link](this);
add(lifeline);
//This is for next button
submit = new JButton("Submit");
[Link](900, 500, 200, 40);
[Link](new Font("Tahoma", [Link], 22));
[Link](new Color(30, 144, 255));
[Link]([Link]);
[Link](this);
[Link](false);//to disable submit Button
add(submit);
//function when question start
start(count);//start from quetion 1
setVisible(true);
}
public void actionPerformed(ActionEvent ae){
if([Link]() == next){
repaint();
[Link](true);
[Link](true);
[Link](true);
[Link](true);
ans_given = 1;
if ([Link]() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = [Link]().getActionCommand();
}
if(count == 8){
[Link](false);
[Link](true);
}
count++;
start(count);
}else if([Link]() == lifeline){
if (count == 2 || count == 4 || count == 6 || count == 8 || count ==9 ){
[Link](false);
[Link](false);
}else {
[Link](false);
[Link](false);
}
[Link](false);//this disable the lifeline buttton after clicking once
}else if ([Link]() == submit){
ans_given = 1;
if ([Link]() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = [Link]().getActionCommand();
}
//this loop is for answers to show after submission
for(int i = 0; i < [Link]; i++){
if(useranswers[i][0].equals(answers[i][1])){
score += 10;//if ans true then he will get 10
}else{
score+=0;//if ans wrong then he will get 0
}
}
//to calculate total score to display
setVisible(false);
new Score(name, score);
}
}
// for timer
public void paint(Graphics g){
[Link](g);
String time = " Time left " + timer + " seconds "; //15
[Link]([Link]);
[Link](new Font("Tahoma", [Link],25));//to show timer bold
if (timer > 0 ){
[Link](time, 850, 400);
}else{
[Link]("Times up!!", 850, 400);//this show times up
}
timer--;//14
try{
[Link](1000);
repaint();//repaints the value of seconds
}catch (Exception e){
[Link]();
}
if (ans_given == 1){
ans_given = 0;
timer = 15;
}else if(timer < 0){
timer = 15;
[Link](true);
[Link](true);
[Link](true);
[Link](true);
if(count == 8){
[Link](false);
[Link](true);
}
if(count == 9){//submit button case
if ([Link]() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = [Link]().getActionCommand();
}
//this loop is for answers to show after submission
for(int i = 0; i < [Link]; i++){
if(useranswers[i][0].equals(answers[i][1])){
score += 10;//if ans true then he will get 10
}else{
score+=0;//if ans wrong then he will get 0
}
}
//to calculate total score to display
setVisible(false);
new Score(name, score);
}else {//next button case
if ([Link]() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = [Link]().getActionCommand();
}
count++;//0//1
start(count);
}
}
public void start(int count){
[Link]("" + (count + 1) + ". ");//Increase count by 1 to next qes
[Link](questions[count][0]);
[Link](questions[count][1]);
[Link](questions[count][1]);
[Link](questions[count][2]);
[Link](questions[count][2]);
[Link](questions[count][3]);
[Link](questions[count][3]);
[Link](questions[count][4]);
[Link](questions[count][4]);
[Link]();
}
public static void main(String[] args){
new Quiz("User");
}
OUTPUT
Score. Java
package [Link];
import [Link].*;
import [Link].*;
import [Link].*;
public class Score extends JFrame implements ActionListener {
Score(String name, int score){
setBounds(400, 150, 750, 550);
getContentPane().setBackground([Link]);
setLayout(null);
ImageIcon i1 = new ImageIcon([Link]("icons/[Link]"));
Image i2 = [Link]().getScaledInstance(300, 250, Image.SCALE_DEFAULT);
ImageIcon i3 = new ImageIcon(i2);
JLabel image = new JLabel(i3);
[Link](0, 200, 300, 250);
add(image);
JLabel heading = new JLabel("Thankyou " + name + " for playing Simple Minds");
[Link](45, 30, 700, 30);
[Link](new Font("Tahoma", [Link], 26));
add(heading);
JLabel lblscore = new JLabel("Your Score is " + score);
[Link](350, 200, 300, 30);
[Link](new Font("Tahoma", [Link], 26));
add(lblscore);
//This is for next button
JButton submit = new JButton("play Again");
[Link](380, 270, 120, 30);
[Link](new Color(30, 144, 255));
[Link]([Link]);
[Link](this);
add(submit);
setVisible(true);//this helps to show the frame
}
public void actionPerformed(ActionEvent ae){
setVisible(false);
new Login();
}
public static void main(String[] args){
new Score("User ", 0);
}
}
OUTPUT