Java Project File
Java Project File
Login. Java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Login extends JFrame implements ActionListener{
Login(){
getContentPane().setBackground(Color.WHITE);
setLayout(null);//It helps to set layout by your own
//size of frame
setSize(1200,500); //width and height of frame
setLocation(200,150);
setVisible(true);// to show Frame
}
}
}
public static void main(String[] args){
new Login();
}
}
OUTPUT
Rules. Java
package quiz.application;
import javax.swing.*;
import java.awt.*;//This import color class
import java.awt.event.*;
);
add(rules);
setSize(800, 650);
setLocation(350, 100);
setVisible(true);
}
}
}
OUTPUT
Quiz. Java
package quiz.application;
import java.awt.Color;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
String name;
Quiz(String name){
this.name = name;
setBounds(40, 0, 1200, 650);
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";
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 {
opt1.setEnabled(false);
opt4.setEnabled(false);
}
lifeline.setEnabled(false);//this disable the lifeline buttton after clicking once
if (groupoptions.getSelection() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
//this loop is for answers to show after submission
for(int i = 0; i < useranswers.length; 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){
super.paint(g);
String time = " Time left " + timer + " seconds "; //15
g.setColor(Color.red);
g.setFont(new Font("Tahoma", Font.BOLD,25));//to show timer bold
if (timer > 0 ){
g.drawString(time, 850, 400);
}else{
g.drawString("Times up!!", 850, 400);//this show times up
}
timer--;//14
try{
Thread.sleep(1000);
repaint();//repaints the value of seconds
}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);
}
}else{
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
//this loop is for answers to show after submission
for(int i = 0; i < useranswers.length; 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);
if (groupoptions.getSelection() == null){
useranswers[count][0] = "";
}else{
useranswers[count][0] = groupoptions.getSelection().getActionCommand();
}
count++;//0//1
start(count);
}
}
opt2.setText(questions[count][2]);
opt2.setActionCommand(questions[count][2]);
opt3.setText(questions[count][3]);
opt3.setActionCommand(questions[count][3]);
opt4.setText(questions[count][4]);
opt4.setActionCommand(questions[count][4]);
groupoptions.clearSelection();
}
OUTPUT
Score. Java
package quiz.application;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
}
public void actionPerformed(ActionEvent ae){
setVisible(false);
new Login();
}
public static void main(String[] args){
new Score("User ", 0);
}
}
OUTPUT