an2kenz_143 0 Newbie Poster

ahmmm i have a few problem in my java game... my game is a quiz game..can u help me? .. or track it? heres my code...

package Games;

import javax.swing.*;

import java.awt.*;
import java.awt.event.*;

public class QandASample extends JWindow implements ActionListener {
	JWindow window = new JWindow();
	JFrame que1 = new JFrame();
	JFrame que2 = new JFrame();
	JFrame que3 = new JFrame();
	JFrame que4 = new JFrame();
	JFrame que5 = new JFrame();
	JFrame res1 = new JFrame();

	JLabel Q1 = new JLabel("1.What is Java (in regard to Computer Science)?");
	JLabel Q2 = new JLabel(
			"2.What's the difference between an Applet and an application ?");
	JLabel Q3 = new JLabel(
			"3.What shortcut we use for importing objects in 'Eclipse' IDE?");
	JLabel Q4 = new JLabel(
			"4.What shortcut we use to compile & run a source code in 'Eclipse' IDE?");
	JLabel Q5 = new JLabel("5.What is the current version for 'JDK' Kit?");
	JLabel label95 = new JLabel("");
	JLabel label96 = new JLabel("");
	JLabel label97 = new JLabel("");
	JLabel label98 = new JLabel("");
	JLabel label99 = new JLabel("");
	JLabel label934 = new JLabel("");
	JLabel TotalQuestion = new JLabel("");
	JLabel labelCorrect = new JLabel("");
	JLabel labelInCorrect = new JLabel("");
	JLabel TotalCorrect = new JLabel("");

	JRadioButton q1a = new JRadioButton("a. A type of Coffee");
	JRadioButton q1b = new JRadioButton("b. Object Oriented Programming");
	JRadioButton q1c = new JRadioButton("c. InterActive Website");
	JRadioButton q1d = new JRadioButton("d. None Of the Above ");

	JRadioButton q2a = new JRadioButton(
			"a. An application is only available on Windows");
	JRadioButton q2b = new JRadioButton(
			"b. Applets can paint words, applications cannot");
	JRadioButton q2c = new JRadioButton("c. Applets are run over the web");
	JRadioButton q2d = new JRadioButton("d. None Of the Above");

	JRadioButton q3a = new JRadioButton("a. CTRL + O");
	JRadioButton q3b = new JRadioButton("b. ALT + O");
	JRadioButton q3c = new JRadioButton("c. CTRL + SHIFT + O");
	JRadioButton q3d = new JRadioButton("d. ALT + SHIFT + O");

	JRadioButton q4a = new JRadioButton("a. ALT + SHIFT + X and J");
	JRadioButton q4b = new JRadioButton("b. CTRL + SHIFT + J and X");
	JRadioButton q4c = new JRadioButton("c. CTRL + ALT + J and Q");
	JRadioButton q4d = new JRadioButton("d. ALT + CTRL + Q");

	JRadioButton q5a = new JRadioButton("a. JDK 1.4 Update 1");
	JRadioButton q5b = new JRadioButton("b. JDK 1.5 Update 10");
	JRadioButton q5c = new JRadioButton("c. JDK 1.6 Update 9");
	JRadioButton q5d = new JRadioButton("d. JDK 1.6 Update 3");

	JButton q1button = new JButton("NEXT");
	JButton q2button = new JButton("NEXT");
	JButton q3button = new JButton("NEXT");
	JButton q4button = new JButton("NEXT");
	JButton q5button = new JButton("NEXT");
	JButton button3 = new JButton("Click to submit your score");
	ButtonGroup g = new ButtonGroup();

	public QandASample() {

		que1.setSize(600, 550);
		que1.setUndecorated(true);
		que1.setLayout(null);
		que1.setAlwaysOnTop(false);
		que1.setResizable(false);
		que1.setTitle("Question1");
		Q1.setBounds(200, 200, 500, 30);
		que1.add(Q1);
		q1a.setBounds(50, 300, 500, 30);
		que1.add(q1a);
		q1b.setBounds(50, 340, 500, 30);
		que1.add(q1b);
		q1c.setBounds(50, 380, 500, 30);
		que1.add(q1c);
		q1d.setBounds(50, 420, 500, 30);
		que1.add(q1d);
		q1button.setBounds(80, 460, 90, 30);
		que1.add(q1button);
		que1.setLocationRelativeTo(null);

		ImageIcon imgBackG = new ImageIcon(getClass().getResource("iwww.jpg"));
		JLabel lblBackG = new JLabel(imgBackG);
		lblBackG.setBounds(0, 0, 600, 600);
		que1.add(lblBackG);
		que1.setVisible(true);

		q1a.addActionListener(this);
		q1b.addActionListener(this);
		q1c.addActionListener(this);
		q1button.addActionListener(this);

		g.add(q1a);
		g.add(q1b);
		g.add(q1c);
		g.add(q1d);

		que2.setUndecorated(true);
		que2.setSize(600, 550);
		que2.setLayout(null);
		que2.setResizable(false);
		que2.setTitle("Question2");
		Q2.setBounds(200, 200, 500, 30);
		que2.add(Q2);
		q2a.setBounds(50, 300, 500, 30);
		que2.add(q2a);
		q2b.setBounds(50, 340, 500, 30);
		que2.add(q2b);
		q2c.setBounds(50, 380, 500, 30);
		que2.add(q2c);
		q2d.setBounds(50, 420, 500, 30);
		que2.add(q2d);
		q2button.setBounds(80, 460, 90, 30);
		que2.add(q2button);
		que2.setLocationRelativeTo(null);

		ImageIcon imageq2 = new ImageIcon(getClass().getResource("iwww.jpg"));
		JLabel lblBackq2 = new JLabel(imageq2);
		lblBackq2.setBounds(0, 0, 600, 600);
		que2.add(lblBackq2);
		que2.setVisible(false);

		q2a.addActionListener(this);
		q2b.addActionListener(this);
		q2c.addActionListener(this);
		q2d.addActionListener(this);
		q2button.addActionListener(this);

		g.add(q2a);
		g.add(q2b);
		g.add(q2c);
		g.add(q2d);

		que3.setUndecorated(true);
		que3.setSize(600, 550);
		que3.setLayout(null);
		que3.setResizable(false);
		que3.setTitle("Question 3");
		Q3.setBounds(200, 200, 500, 30);
		que3.add(Q3);
		q3a.setBounds(50, 300, 500, 30);
		que3.add(q3a);
		q3b.setBounds(50, 340, 500, 30);
		que3.add(q3b);
		q3c.setBounds(50, 380, 500, 30);
		que3.add(q3c);
		q3d.setBounds(50, 420, 500, 30);
		que3.add(q3d);
		q3button.setBounds(80, 460, 90, 30);
		que3.add(q3button);
		que3.setLocationRelativeTo(null);

		ImageIcon imageq3 = new ImageIcon(getClass().getResource("iwww.jpg"));
		JLabel lblBackq3 = new JLabel(imageq3);
		lblBackq3.setBounds(0, 0, 600, 600);
		que3.add(lblBackq3);
		que3.setVisible(false);

		q3a.addActionListener(this);
		q3b.addActionListener(this);
		q3c.addActionListener(this);
		q3d.addActionListener(this);
		q3button.addActionListener(this);

		g.add(q3a);
		g.add(q3b);
		g.add(q3c);
		g.add(q3d);

		que4.setUndecorated(true);
		que4.setSize(600, 550);
		que4.setLayout(null);
		que4.setResizable(false);
		que4.setTitle("Question4");
		Q4.setBounds(200, 200, 500, 30);
		que4.add(Q4);
		q4a.setBounds(50, 300, 500, 30);
		que4.add(q4a);
		q4b.setBounds(50, 340, 500, 30);
		que4.add(q4b);
		q4c.setBounds(50, 380, 500, 30);
		que4.add(q4c);
		q4d.setBounds(50, 420, 500, 30);
		que4.add(q4d);
		q4button.setBounds(80, 460, 90, 30);
		que4.add(q4button);
		que4.setLocationRelativeTo(null);

		ImageIcon imageq4 = new ImageIcon(getClass().getResource("iwww.jpg"));
		JLabel lblBackq4 = new JLabel(imageq4);
		lblBackq4.setBounds(0, 0, 600, 600);
		que4.add(lblBackq4);
		que4.setVisible(false);

		q4a.addActionListener(this);
		q4b.addActionListener(this);
		q4c.addActionListener(this);
		q4d.addActionListener(this);
		q4button.addActionListener(this);

		g.add(q4a);
		g.add(q4b);
		g.add(q4c);
		g.add(q4d);

		que5.setUndecorated(true);
		que5.setSize(600, 550);
		que5.setLayout(null);
		que5.setResizable(false);
		que5.setTitle("Question5");
		Q5.setBounds(200, 200, 500, 30);
		que5.add(Q5);
		q5a.setBounds(50, 300, 500, 30);
		que5.add(q5a);
		q5b.setBounds(50, 340, 500, 30);
		que5.add(q5b);
		q5c.setBounds(50, 380, 500, 30);
		que5.add(q5c);
		q5d.setBounds(50, 420, 500, 30);
		que5.add(q5d);
		q5button.setBounds(80, 460, 90, 30);
		que5.add(q5button);
		que5.setLocationRelativeTo(null);

		ImageIcon imageq5 = new ImageIcon(getClass().getResource("iwww.jpg"));
		JLabel lblBackq5 = new JLabel(imageq5);
		lblBackq5.setBounds(0, 0, 600, 600);
		que5.add(lblBackq5);
		que5.setVisible(false);

		q5a.addActionListener(this);
		q5b.addActionListener(this);
		q5c.addActionListener(this);
		q5d.addActionListener(this);
		q5button.addActionListener(this);

		g.add(q5a);
		g.add(q5b);
		g.add(q5c);
		g.add(q5d);

		res1.setSize(600, 600);
		res1.setLayout(null);
		res1.setResizable(false);
		res1.setTitle("Result");
		label99.setBounds(20, 50, 500, 30);
		res1.add(label99);
		label98.setBounds(20, 100, 500, 30);
		res1.add(label98);
		label97.setBounds(20, 150, 500, 30);
		res1.add(label97);
		label95.setBounds(20, 200, 500, 30);
		res1.add(label95);
		TotalQuestion.setBounds(20, 250, 500, 30);
		res1.add(TotalQuestion);
		labelCorrect.setBounds(20, 300, 500, 30);
		res1.add(labelCorrect);
		labelInCorrect.setBounds(20, 350, 500, 30);
		res1.add(labelInCorrect);
		TotalCorrect.setBounds(20, 400, 500, 30);
		res1.add(TotalCorrect);
		label96.setBounds(20, 450, 500, 30);
		res1.add(label96);
		button3.setBounds(30, 500, 400, 30);
		res1.add(button3);
		res1.setLocationRelativeTo(null);

		ImageIcon imageresult = new ImageIcon(getClass().getResource("awt.jpg"));
		JLabel lblresult = new JLabel(imageresult);
		lblresult.setBounds(0, 0, 600, 600);
		res1.add(lblresult);

		que1.setVisible(false);

		button3.setActionCommand("button3");
		button3.addActionListener(this);
		que1.setVisible(true);
		que5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	}

	public void actionPerformed(ActionEvent e) {
		Object source = e.getSource();

		int que1a = 0, que1b = 0, que1c = 0, que1d = 0;
		int que2a = 0, que2b = 0, que2c = 0, que2d = 0;
		int que3a = 0, que3b = 0, que3c = 0, que3d = 0;
		int que4a = 0, que4b = 0, que4c = 0, que4d = 0;
		int que5a = 0, que5b = 0, que5c = 0, que5d = 0;
		
		int i = 0;
		int s = 0;
		
		
		if (q1a.isSelected()) {
			
			que1a++;	
		}
		else if (q1b.isSelected()) {
			
			que1b++;
		}

		else if (q1c.isSelected()) {
			
			que1c++;

		} else if (q1d.isSelected()) {
			
			que1d++;

		}

		if (q2a.isSelected()) 
		{
			
			que2a++;
		} else if (q2b.isSelected()) {

			que2b++;
		}

		else if (q2c.isSelected()) {

			que2c++;

		} else if (q2d.isSelected()) {

			que2d++;

		}

		if (q3a.isSelected()) {
			que3a++;
		} else if (q3b.isSelected()) {

			que3b++;
		}

		else if (q3c.isSelected()) {

			que3c++;

		} else if (q3d.isSelected()) {

			que3d++;

		}

		if (q4a.isSelected()) {
			que4a++;
		} else if (q4b.isSelected()) {

			que4b++;
		}

		else if (q4c.isSelected()) {

			que4c++;

		} else if (q4d.isSelected()) {

			que4d++;

		}

		if (q5a.isSelected())
		{
			que5a++;
		} else if (q5b.isSelected()) {

			que5b++;
		}

		else if (q5c.isSelected()) {

			que5c++;

		} else if (q5d.isSelected()) {

			que5d++;

		}

		

		if (source == q1button) {
				
			if (i > 1) {
				i = i + 1;
			}
			if (s > 1) {
				s = s + 1;
			}
			que1.setVisible(false);
			que2.setVisible(true);
			que3.setVisible(false);
			que4.setVisible(false);
			que5.setVisible(false);
		}

		if (source == q2button) {
			if (i > 1) {
				i = i + 1;
			}
			if (s > 1) {
				s = s + 1;
			}
			que1.setVisible(false);
			que2.setVisible(false);
			que3.setVisible(true);
			que4.setVisible(false);
			que5.setVisible(false);
		}
		if (source == q3button) {
			if (i > 1) {
				i = i + 1;
			}
			if (s > 1) {
				s = s + 1;
			}
			que1.setVisible(false);
			que2.setVisible(false);
			que3.setVisible(false);
			que4.setVisible(true);
			que5.setVisible(false);
			res1.setVisible(false);
		}
		if (source == q4button) {
			if (i > 1) {
				i = i + 1;
			}
			if (s > 1) {
				s = s + 1;
			}
			que1.setVisible(false);
			que2.setVisible(false);
			que3.setVisible(false);
			que4.setVisible(false);
			que5.setVisible(true);
			res1.setVisible(false);
		}

		if (source == q5button) {
			if (i > 1) {
				i = i + 1;
			}
			if (s > 1) {
				s = s + 1;
			}
			que1.setVisible(false);
			que2.setVisible(false);
			que3.setVisible(false);
			que4.setVisible(false);
			que5.setVisible(false);
			res1.setVisible(true);
			
			
		}
		
		int totala = que1a + que2a + que3a + que4a + que5a;
		int totalb = que1b + que2b + que3b + que4b + que5b;
		int totalc = que1c + que2c + que3c + que4c + que5c;
		int totald = que1d + que2d + que3d + que4d + que5d;

		int totaltotal = totala + totalb + totalc + totald;
		
		
		label99.setText("Total number of As selected: " + totala);
		label98.setText("Total number of Bs selected: " + totalb);
		label97.setText("Total number of Cs selected: " + totalc);
		label95.setText("Total number of Ds selected: " + totald);
		TotalQuestion.setText("Total Question :  5" );
		labelCorrect.setText("Total number of Correct : " + s);
		labelInCorrect.setText("Total number of InCorrect");
		TotalCorrect.setText("Total Percent : ");

		
		if (source == button3) {
			label96.setText("Your total Score:" + totaltotal);
			label934.setText("" + totaltotal);

		}

	}

	public static void main(String[] args) {
		new QandASample();
	}
}

heres my question... how can i get the total question, total number of correction, total number of incorrect answer and the total percent of my game??? can u give me a good syntax for this?also how to implement a timer for that... thx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.