Java quiz game ⌛

preview_player
Показать описание
Java how to make a multiple choice quiz/test in Java tutorial

#Java #quiz #tutorial #game #beginner

Coding boot camps hate him! See how he can teach you to code with this one simple trick...

Bro Code is the self-proclaimed #1 tutorial series on coding in various programming languages and other how to videos in the known universe.
Рекомендации по теме
Комментарии
Автор

// Main
public class Main {

public static void main(String[] args) {

Quiz quiz = new Quiz();
}
}
// Quiz
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;

public class Quiz implements ActionListener{

String[] questions = {
company created Java?",
year was Java created?",
was Java originally called?",
is credited with creating Java?"

String[][] options = {
Microsystems", "Starbucks", "Microsoft", "Alphabet"},


Jobs", "Bill Gates", "James Gosling", "Mark Zuckerburg"}

char[] answers = {





char guess;
char answer;
int index;
int correct_guesses =0;
int total_questions = questions.length;
int result;
int seconds=10;

JFrame frame = new JFrame();
JTextField textfield = new JTextField();
JTextArea textarea = new JTextArea();
JButton buttonA = new JButton();
JButton buttonB = new JButton();
JButton buttonC = new JButton();
JButton buttonD = new JButton();
JLabel answer_labelA = new JLabel();
JLabel answer_labelB = new JLabel();
JLabel answer_labelC = new JLabel();
JLabel answer_labelD = new JLabel();
JLabel time_label = new JLabel();
JLabel seconds_left = new JLabel();
JTextField number_right = new JTextField();
JTextField percentage = new JTextField();

Timer timer = new Timer(1000, new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
seconds--;

if(seconds<=0) {
displayAnswer();
}
}
});

public Quiz() {

frame.setSize(650, 650);
Color(50, 50, 50));
frame.setLayout(null);
frame.setResizable(false);

textfield.setBounds(0, 0, 650, 50);
textfield.setBackground(new Color(25, 25, 25));
textfield.setForeground(new Color(25, 255, 0));
textfield.setFont(new Font("Ink Free", Font.BOLD, 30));




textarea.setBounds(0, 50, 650, 50);


textarea.setBackground(new Color(25, 25, 25));
textarea.setForeground(new Color(25, 255, 0));
textarea.setFont(new Font("MV Boli", Font.BOLD, 25));



buttonA.setBounds(0, 100, 100, 100);
buttonA.setFont(new Font("MV Boli", Font.BOLD, 35));


buttonA.setText("A");

buttonB.setBounds(0, 200, 100, 100);
buttonB.setFont(new Font("MV Boli", Font.BOLD, 35));


buttonB.setText("B");

buttonC.setBounds(0, 300, 100, 100);
buttonC.setFont(new Font("MV Boli", Font.BOLD, 35));


buttonC.setText("C");

buttonD.setBounds(0, 400, 100, 100);
buttonD.setFont(new Font("MV Boli", Font.BOLD, 35));


buttonD.setText("D");

answer_labelA.setBounds(125, 100, 500, 100);
Color(50, 50, 50));
Color(25, 255, 0));
answer_labelA.setFont(new Font("MV Boli", Font.PLAIN, 35));

answer_labelB.setBounds(125, 200, 500, 100);
Color(50, 50, 50));
Color(25, 255, 0));
answer_labelB.setFont(new Font("MV Boli", Font.PLAIN, 35));

answer_labelC.setBounds(125, 300, 500, 100);
Color(50, 50, 50));
Color(25, 255, 0));
answer_labelC.setFont(new Font("MV Boli", Font.PLAIN, 35));

answer_labelD.setBounds(125, 400, 500, 100);
Color(50, 50, 50));
Color(25, 255, 0));
answer_labelD.setFont(new Font("MV Boli", Font.PLAIN, 35));

seconds_left.setBounds(535, 510, 100, 100);
Color(25, 25, 25));
Color(255, 0, 0));
seconds_left.setFont(new Font("Ink Free", Font.BOLD, 60));





time_label.setBounds(535, 475, 100, 25);
Color(50, 50, 50));
Color(255, 0, 0));
time_label.setFont(new Font("MV Boli", Font.PLAIN, 16));

time_label.setText("timer >:D");

number_right.setBounds(225, 225, 200, 100);
Color(25, 25, 25));
Color(25, 255, 0));
number_right.setFont(new Font("Ink Free", Font.BOLD, 50));




percentage.setBounds(225, 325, 200, 100);
Color(25, 25, 25));
Color(25, 255, 0));
percentage.setFont(new Font("Ink Free", Font.BOLD, 50));




frame.add(time_label);
frame.add(seconds_left);
frame.add(answer_labelA);
frame.add(answer_labelB);
frame.add(answer_labelC);
frame.add(answer_labelD);
frame.add(buttonA);
frame.add(buttonB);
frame.add(buttonC);
frame.add(buttonD);
frame.add(textarea);
frame.add(textfield);
frame.setVisible(true);

nextQuestion();
}
public void nextQuestion() {

if(index>=total_questions) {
results();
}
else {
"+(index+1));





timer.start();
}
}
@Override
public void actionPerformed(ActionEvent e) {






if(e.getSource()==buttonA) {
answer= 'A';
if(answer == answers[index]) {

}
}
if(e.getSource()==buttonB) {
answer= 'B';
if(answer == answers[index]) {

}
}
if(e.getSource()==buttonC) {
answer= 'C';
if(answer == answers[index]) {

}
}
if(e.getSource()==buttonD) {
answer= 'D';
if(answer == answers[index]) {

}
}
displayAnswer();
}
public void displayAnswer() {

timer.stop();

buttonA.setEnabled(false);
buttonB.setEnabled(false);
buttonC.setEnabled(false);
buttonD.setEnabled(false);

if(answers[index] != 'A')
Color(255, 0, 0));
if(answers[index] != 'B')
Color(255, 0, 0));
if(answers[index] != 'C')
Color(255, 0, 0));
if(answers[index] != 'D')
Color(255, 0, 0));

Timer pause = new Timer(2000, new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

Color(25, 255, 0));
Color(25, 255, 0));
Color(25, 255, 0));
Color(25, 255, 0));

answer = ' ';
seconds=10;





index++;
nextQuestion();
}
});
pause.setRepeats(false);
pause.start();
}
public void results(){

buttonA.setEnabled(false);
buttonB.setEnabled(false);
buttonC.setEnabled(false);
buttonD.setEnabled(false);

result =


textarea.setText("");
answer_labelA.setText("");
answer_labelB.setText("");
answer_labelC.setText("");
answer_labelD.setText("");




frame.add(number_right);
frame.add(percentage);

}
}

BroCodez
Автор

Hey mate, this is the most valuable tutorial on Java. The reason most people give up on coding is they never start because they want to understand more before starting.
This is very straight forward and allows to actually start coding and before you realize it you are actually a coder.

jcarc
Автор

easily one of the most underrated coding channels, i hope you make it big one day :)

TheTechdude
Автор

Thank sir for giving us the quality education for free of cost 🥺
And the video is awesome😊

VikramKumar.
Автор

I made this for my Univerity project, nice project and teaching ideas

amarshgautam
Автор

I found the constructor a bit overwhelming, so I did this:

set_frame();
set_textfield();
set_textarea();
set_buttons();
set_answer_labels();
set_timer();
set_seconds_left();
set_number_right();
set_percentage();
frame_add();


and one method as an example:

public void set_frame()
{

frame.setSize(600, 600);
Color(150, 150, 150));
frame.setLayout(null);
frame.setResizable(false);
}

stephanieezat-panah
Автор

Bro, your projects are really helping me understand Java. TYVM.

rjmp
Автор

Dude, ur tutorials are what I am really looking for, ez for understanding, ez to follow! Best Tutorial for beginners!

stephenlai
Автор

Yeah I enjoyed the lesson💯%, Thank you Bro🙂🙂

Hezronmaina-md
Автор

best channel so far. Thanks mate! helps us a lot!

joffwillardvaldez
Автор

This was awesome! I think I am going to try to take this and run with it, and expand it to really follow the rules of OOP, and encapsulate everything into the proper classes and methods. This is a great starting place!

WretchedByNature
Автор

Keep sharing these wonderful works
I'll always support you🌹🌹

mr_robert
Автор

This video explains all concept of swing. Thanks for making this amazing video. I understand a lot👍👍

adityabasanti
Автор

The perfect video that I was looking for ! Bro, will you also start teaching android app development from zero to hero level !! 😎 Both offline & online apps. Thanks in advance 👍

supreme-soft
Автор

Hey man, I'm just jumping back into programming and I'm really enjoying messing around with this and refactoring it to try and make a real game out of it, thanks for posting this!

Quest-Giver
Автор

If GIGA-CHAD was a programmer, he would be Bro Code!

raannyaana
Автор

Dropping my comment bro !!! 👍🎄Merry Christmas n Happy New year🎄

aruldilip
Автор

The very best java tutorial channel on YT..ok maybe in World 🤔
Thank you for all the effort you put in your videos!:)

superTramp
Автор

Thumbnail: Will you click on this video ?

Me: yea

abhilashLeader_
Автор

I SUBSCRIBE AND I COMMENT IS THE BEST GUY WHO EXPLAIN ON THE INTERNET

unda