View Single Post
Old Oct 1st, 2007, 4:47 AM   #10
bratsercom
Newbie
 
Join Date: Sep 2007
Posts: 6
Rep Power: 0 bratsercom is an unknown quantity at this point
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.Properties;
 
 
public class QuizGame extends JFrame implements ActionListener {
	
	Container MyBox = getContentPane(); 
	
	JPanel textareaPanel = new JPanel();
	JPanel buttonsPanel = new JPanel();
	
	JTextArea textarea = new JTextArea(15,30);
	JScrollPane scroll = new JScrollPane( textarea);
	
	JButton Answer1 = new JButton( "Answer 1");
	JButton Answer2 = new JButton( "Answer 2");
	JButton Answer3	= new JButton( "Answer 3");
	JButton Answer4 = new JButton( "Answer 4");
	JButton NextQuestion = new JButton( "Next Question");
	JButton Exit = new JButton ( "Exit");
	String AppExit = "";
	String question = "";
	String answer1 = "";
	String answer2 = "";
	String answer3 = "";
	String answer4 = "";
	String correctAnswer = "";
	String userAnswer = "";
 
	
	public QuizGame() 
	{
		super ("The Quiz");
		setSize(400,500);
		JOptionPane.showMessageDialog(null, "Welcome to \"The Quiz\" PRE-Alpha");
	}
	
	public void GUI()
	{
	 	MyBox.setLayout(new BorderLayout());
 		MyBox.setBackground(Color.black);
 		MyBox.add(textareaPanel, BorderLayout.NORTH);
 		MyBox.add(buttonsPanel, BorderLayout.CENTER);
 	
 		buttonsPanel.setLayout(new GridLayout(2,3));
 		
 		textareaPanel.add(textarea);
 		
 		textarea.setEditable(false);
 		
 		buttonsPanel.setBackground(Color.black);
 		buttonsPanel.add(Answer1, BorderLayout.CENTER );
 		buttonsPanel.add(Answer3, BorderLayout.CENTER);
		buttonsPanel.add(NextQuestion, BorderLayout.WEST);
		buttonsPanel.add(Answer2, BorderLayout.WEST);
		buttonsPanel.add(Answer4, BorderLayout.WEST);
		buttonsPanel.add(Exit, BorderLayout.EAST);
		
		Answer1.addActionListener(this);
		Answer2.addActionListener(this);
		Answer3.addActionListener(this);
		Answer4.addActionListener(this);
		NextQuestion.addActionListener(this);
		Exit.addActionListener(this);
	}
	
	public void Properties()
	{ 
	
		Properties questionProperties = new Properties();
		FileReader questionIn = new FileReader(new File("P:\\Quiz\\QuizGame\\question.txt"));
		questionProperties.read(questionIn);
 

		String question = questionProperties.getProperty("question.txt");
		String answer1 = questionProperties.getProperty("answer.1");
		String answer2 = questionProperties.getProperty("answer.2");
		String answer3 = questionProperties.getProperty("answer.3");
		String answer4 = questionProperties.getProperty("answer.4");
		String correctAnswer = questionProperties.getProperty("answer.correct");
		
		textarea.append(question+"\n\n"+answer1+"\n"+answer2+"\n"+answer3+"\n"+answer4);
	}
	
	
	public void actionPerformed(ActionEvent event)
	{
		if ( event.getActionCommand().equals("Answer 1"))
		{
			userAnswer = answer1;
			if (userAnswer.equals(correctAnswer)) 
			{
				JOptionPane.showMessageDialog(null, "Correct!");
			}
			else
			{
				JOptionPane.showMessageDialog(null, "You're wrong!");
			}
		}
		if ( event.getActionCommand().equals("Answer 2"))
		{
			userAnswer = answer2;
			if (userAnswer.equals(correctAnswer)) 
			{
				JOptionPane.showMessageDialog(null, "Correct!");
			}
			else
			{
				JOptionPane.showMessageDialog(null, "You're wrong!");
			}
		}
		if ( event.getActionCommand().equals("Answer 3"))
		{
			userAnswer = answer3;
			if (userAnswer.equals(correctAnswer)) 
			{
				JOptionPane.showMessageDialog(null, "Correct!");
			}
			else
			{
				JOptionPane.showMessageDialog(null, "You're wrong!");
			}
		}
		if ( event.getActionCommand().equals("Answer 4"))
		{
			userAnswer = answer4;
			if (userAnswer.equals(correctAnswer)) 
			{
				JOptionPane.showMessageDialog(null, "Correct!");
			}
			else
			{
				JOptionPane.showMessageDialog(null, "You're wrong!");
			}
		}
		
		if ( event.getActionCommand().equals("Exit"))
		{
			JOptionPane.showMessageDialog(null, "Thank you for using\"The Quiz\"");
			System.exit(0);
		}
		
		if ( event.getActionCommand().equals("Next Question"))
		{
			JOptionPane.showMessageDialog(null, "Still Working on it!");
		}
	}
 
	public void init()
	{
	  	//
	}
	
	public static void main(String args[])
	{		
		QuizGame object = new QuizGame();
 		object.GUI();
 		object.Properties();
 		object.setVisible(true);
 		
	}
}

Quote:
--------------------Configuration: <Default>--------------------
C:\QuizGame.java:75: cannot resolve symbol
symbol : method read (java.io.FileReader)
location: class java.util.Properties
questionProperties.read(questionIn);
^
1 error

Process completed.
i got this one but it has a problem \..

someone help me please

Last edited by big_k105; Oct 1st, 2007 at 2:29 PM. Reason: Added Code Tags
bratsercom is offline   Reply With Quote