Wednesday, December 20, 2006

Wednesday's Work Log
-------------------------

Sample code as follows:

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();
FileInputStream questionIn = new FileInputStream(new File("P:\\Quiz\\QuizGame\\question.txt"));
BufferedInputStream bis = new BufferedInputStream(questionIn);
questionProperties.load(bis);

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);

}
}

Still working on how to embed video into a Java applet.

Tuesday, December 19, 2006

Work begins on new Final CPT Project

Check this space for more info.

Tuesday, December 12, 2006

Well my Pig Latin Assignment is complete. The next step right now is adding a function that allows it to translate text typed within the window, not just imported text from a file.

Here it is:
Image Hosted by ImageShack.us

Tuesday, December 05, 2006

Progress on Pig Latin assignment:

Have source files to work with. Keep checking this space.
Currently Working on...........


PIG LATIN ASSIGNMENT

BURN ZE PIGS!!!

lol j/k