Quiz program in java using awt source code: This simple quiz project in core java code with the use of AWT class. We can create a sample quiz contest using this tutorial. This program can be done easily by using the Java AWT class. This java project can be used as a mini project for engineering students and professionals. Project code is given below.
QUIZ CONTEST IN JAVA SWING
This java swing program is used to create a quiz program to test the student’s knowledge by using the set of questions with choices. Students have an ability to answer by selecting the checkbox. We can change the question and answer easily by re-editing the program and answer options.
[Useful: C Programming Guide] & [IT Companies Details]
Simple Quiz Program - Java Swing Code:
Q: Write a java program to create a simple quiz contest using AWT class.
//Import statements
import java.awt.*;
import java.awt.event.*;
//Class definition
class QuizCheck extends Frame implements ActionListener
{
//Variable declaration
Checkbox che1, che2, che3, che4;
Panel pa1,pa2;
Button bu1,bu2;
Label la1;
public QuizCheck(String title)
{
super(title);
pa1=new Panel();//Object creation
pa2=new Panel();
che1=new Checkbox("Charles Babbage");
che2=new Checkbox("Dennis Ritche");
che3=new Checkbox("James Gosling");
che4=new Checkbox("None");
la1=new Label("Q. Who developed Java?");
bu1=new Button("OK");
bu2=new Button("CANCEL");
// © http://students3k.com – Karthikh Venkat
bu1.addActionListener(this);
b2.addActionListener(this);
p1.setLayout(new GridLayout(5,1));
pa1.add(la1);
pa1.add(che1);
pa1.add(che2);
pa1.add(che3);
pa1.add(che4);
pa2.add(bu1);
pa2.add(bu2);
add("West",pa1);
add("South",pa2);
setSize(300,300);
setVisible(true);
}
public static void main(String args[]) {
QuizCheck c=new QuizCheck("QUIZ");
}
// © http://students3k.com – Karthikh Venkat
public void actionPerformed(ActionEvent e)
{
//Decision making statement
if(e.getSource()==bu1)
if(che1.getState()==false && che2.getState()==false && che3.getState()==true &&che4.getState()==false)
javax.swing.JOptionPane.showMessageDialog(this,"Congratulations!");
javax.swing.JOptionPane.showMessageDialog(this,"Sorry! Try again");
else
System.exit(0);
}
}
SEE: All Examination Results & News