Make Simple Exam Project in Java Swing

 

Make Simple Exam Project in Java Swing:

https://youtu.be/peOtUaD82A0 ________________________________________________ How to Make Simple Exam Project in Java Swing?

package Test;


import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


class SimpleExamProject extends JFrame implements ActionListener{

JLabel l;

JRadioButton jb[] = new JRadioButton[5];

JButton b1, b2;

ButtonGroup bg;

int count = 0, current = 0, x = 1, y = 1, now = 0;

int m[] = new int[10];

SimpleExamProject(String s) {

super(s);

l = new JLabel();

add(l);

bg = new ButtonGroup();

for( int i = 0; i < 5; i++) {

jb[i] = new JRadioButton();

add(jb[i]);

bg.add(jb[i]);

}

b1 = new JButton("Next");

b2 = new JButton("Save");

b1.addActionListener(this);

b2.addActionListener(this);

add(b1);

add(b2);

set();

l.setBounds(30,40,450,20);

jb[0].setBounds(50,80,100,20);

jb[1].setBounds(50,110,100,20);

jb[2].setBounds(50,140,100,20);

jb[3].setBounds(50,170,100,20);

b1.setBounds(100,240,100,30);

b2.setBounds(270,240,100,30);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(null);

setLocation(250,100);

setVisible(true);

setSize(600,350);

}

public void actionPerformed(ActionEvent e) {

if(e.getSource() == b1) {

if(check()) {

count = count + 1;

}

current++;

set();

if(current == 9) {

b1.setEnabled(false);

b2.setText("Result");

}

}

if(e.getActionCommand().equals("Save")) {

JButton bk = new JButton("Save" + x);

bk.setBounds(480,20+30*x,100,30);

add(bk);

bk.addActionListener(this);

m[x] = current;

x++;

current++;

set();

if(current == 9) {

b2.setText("Result");

}

setVisible(false);

setVisible(true);

}

for(int i = 0, y = 1; i < x; i++, y++) {

if(e.getActionCommand().equals("Bookmark" + y)) {

if(check()) {

count = count + 1;

}

now = current;

current = m[y];

set();

((JButton) e.getSource()).setEnabled(false);

current = now;

}

}

if(e.getActionCommand().equals("Result")) {

if(check()) {

count = count + 1;

}

current++;

JOptionPane.showMessageDialog(this, "correct answer=" + count);

System.exit(0);

}

}

void set() {

jb[4].setSelected(true);

if(current == 0) {

l.setText("Question1: 5+5=?");

jb[0].setText("10");

jb[1].setText("5");

jb[2].setText("6");

jb[3].setText("20");

}

if(current == 1) {

l.setText("Question2: What is meaning of int?");

jb[0].setText("Interface");

jb[1].setText("Intel");

jb[2].setText("Integer");

jb[3].setText("Interpol");

}

if(current == 2) {

l.setText("Question3: What is meaning of HTML?");

jb[0].setText("Hiddent Text Material Learning");

jb[1].setText("Hard Truck Metal Laboratory");

jb[2].setText("Halloween Trap Mental Laugh");

jb[3].setText("Hyper Text Markup Language");

}

if(current == 3) {

l.setText("Question4: Where is the capital of America?");

jb[0].setText("London");

jb[1].setText("Trump");

jb[2].setText("Washington");

jb[3].setText("Amsterdam");

}

if(current == 4) {

l.setText("Question5: What is meaning of CPU?");

jb[0].setText("Central Processing Unit");

jb[1].setText("Ceremony Pleague Underground");

jb[2].setText("Call of Duty");

jb[3].setText("Central Parlament of Udemy");

}

if(current == 5) {

l.setText("Question6: What is Among US?");

jb[0].setText("Game");

jb[1].setText("Number");

jb[2].setText("City");

jb[3].setText("Gamer");

}

if(current == 6) {

l.setText("Question7: Who is Ghost?");

jb[0].setText("Horror Person");

jb[1].setText("Armed Person");

jb[2].setText("Gamer Person");

jb[3].setText("C.O.D. Person");

}

if(current == 7) {

l.setText("Question8: Hello how are ...?");

jb[0].setText("you");

jb[1].setText("your dog");

jb[2].setText("your family");

jb[3].setText("yours");

}

if(current == 8) {

l.setText("Question9: Imagine that like ...?");

jb[0].setText("Name");

jb[1].setText("Funny");

jb[2].setText("World");

jb[3].setText("I didn't give aaaa");

}

if(current == 9) {

l.setText("Question10: Thanks for ...?");

jb[0].setText("Watching");

jb[1].setText("Laughing");

jb[2].setText("Thinking");

jb[3].setText("Sharing");

}

l.setBounds(30, 40, 450, 20);

for(int i = 0, j = 0; i <= 90; i += 30, j++) {

jb[j].setBounds(50, 80 + i, 200, 20);

}

}

boolean check() {

if(current == 0) {

return(jb[0].isSelected());

}

if(current == 1) {

return(jb[2].isSelected());

}

if(current == 2) {

return(jb[3].isSelected());

}

if(current == 3) {

return(jb[2].isSelected());

}

if(current == 4) {

return(jb[0].isSelected());

}

if(current == 5) {

return(jb[0].isSelected());

}

if(current == 6) {

return(jb[3].isSelected());

}

if(current == 7) {

return(jb[0].isSelected());

}

if(current == 8) {

return(jb[3].isSelected());

}

if(current == 9) {

return(jb[0].isSelected());

}

return false;

}

public static void main(String s[]) {

new SimpleExamProject("Simple Exam Project");

}

}

________________________________________________

Dark Hers

https://darkhers.blogspot.com

YouTube

https://youtube.com/@darkhers

Instagram

https://instagram.com/darkhers

Facebook

https://www.facebook.com/darkhers

TikTok

https://www.tiktok.com/@darkhers

Pinterest

https://www.pinterest.co.uk/darkhers

Twitter

https://twitter.com/Dark_Hers

Comments

Popular Posts