Java M
Java M
Java M
Implementation:
4.1 CODE:
1)Login.java :-
package quiz.application;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Login() {
getContentPane().setBackground(Color.WHITE);
setLayout(null);
setSize(1200, 500);
setLocation(200, 150);
setVisible(true);
}
String name;
JButton start, back;
Rules(String name) {
this.name = name;
getContentPane().setBackground(Color.WHITE);
setLayout(null);
setSize(800, 650);
setLocation(350, 100);
setVisible(true);
}
3)Score.java :-
This is the code for the score which will be displayed after the quiz is over
package quiz.application;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
JLabel heading = new JLabel("Thankyou " + name + " for playing Simple Minds");
heading.setBounds(45, 30, 700, 30);
heading.setFont(new Font("Tahoma", Font.PLAIN, 26));
add(heading);
setVisible(true);
}
4)Quiz.java :-
This is the code for the main Quiz Application
package quiz.application;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
String name;
Quiz(String name) {
this.name = name;
setBounds(50, 0, 1440, 850);
getContentPane().setBackground(Color.WHITE);
setLayout(null);
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[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[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] = "java.util 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] = "java.lang.StringBuilder";
answers[9][1] = "Bytecode is executed by JVM";
start(count);
setVisible(true);
}
ans_given = 1;
if (groupoptions.getSelection() == null) {
useranswers[count][0] = "";
} else {
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
if (count == 8) {
next.setEnabled(false);
submit.setEnabled(true);
}
count++;
start(count);
} else if (ae.getSource() == lifeline) {
if (count == 2 || count == 4 || count == 6 || count == 8 || count == 9) {
opt2.setEnabled(false);
opt3.setEnabled(false);
} else {
opt1.setEnabled(false);
opt4.setEnabled(false);
}
lifeline.setEnabled(false);
} else if (ae.getSource() == submit) {
ans_given = 1;
if (groupoptions.getSelection() == null) {
useranswers[count][0] = "";
} else {
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
if (timer > 0) {
g.drawString(time, 1100, 500);
} else {
g.drawString("Times up!!", 1100, 500);
}
timer--; // 14
try {
Thread.sleep(1000);
repaint();
} catch (Exception e) {
e.printStackTrace();
}
if (ans_given == 1) {
ans_given = 0;
timer = 15;
} else if (timer < 0) {
timer = 15;
opt1.setEnabled(true);
opt2.setEnabled(true);
opt3.setEnabled(true);
opt4.setEnabled(true);
if (count == 8) {
next.setEnabled(false);
submit.setEnabled(true);
}
if (count == 9) { // submit button
if (groupoptions.getSelection() == null) {
useranswers[count][0] = "";
} else {
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
opt3.setText(questions[count][3]);
opt3.setActionCommand(questions[count][3]);
opt4.setText(questions[count][4]);
opt4.setActionCommand(questions[count][4]);
groupoptions.clearSelection();
}
We would like to express our thanks to the Head of Computer Department, Dr. Sanjay N.
Sharma and all other staff members for their encouragement and suggestions.
Last but not the least, we are thankful to our friends for their support and coordination.
We are also thankful to our parents for their constant support and best wishes.
Mangesh Gangurde
Prajwal Nandagawali
Vipul Bailkar
Date :