Purchase Solution

Java memory game program

Not what you're looking for?

Ask Custom Question

I am stumped with this java driver program. I have been able to obtain parts of the first sample session. Please see my progress below.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MemoryProg extends JFrame
{
private static final int WIDTH = 350;
private static final int HEIGHT = 200;
private JTextField nameBox;
//**************************************************************************

public MemoryProg()
{
setTitle("Message");
setSize(WIDTH, HEIGHT);
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
createContents();
setVisible(true);
}
//**************************************************************************

public void createContents()
{
JOptionPane.showInputDialog("Enter color number 1:");
nameBox = new JTextField(15);
add (nameBox);

}
//**************************************************************************
public static void main(String[] args)
{
JOptionPane.showMessageDialog(null, "How good is your memory?
n" +
"Try to memorize this color sequence: nn" +
"red white yellow green blue");
new MemoryProg7();

}
//*************************************************************************
}//end MemoryProg

Attachments
Purchase this Solution

Solution Summary

A java program with a color memory game. When launched you will see a question "How good is your memory? try to memorize following color sequence". Then the form will appear where the user can enter his guess. If the user correctly enters all the colors, the program prints a "Congratulations" message.

Solution Preview

Here is the code. Compiled and tested in NetBeans. Good luck and thanks for using Brainmass.com!

Instructions:
1) Copy the source code below into a text file and name it MemoryProg7.java
2) Compile the code - you can use javac.exe -g MemoryProg7.java
3) Run the program - java.exe MemoryProg7

Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MemoryProg7 extends JApplet {

private static final int WIDTH = 350;
private static final int HEIGHT = 200;

JLabel colLabel=new JLabel("Enter Color Number 1: ");
JTextField colText=new JTextField(8);
JButton butHint=new JButton("Hint");

int colorIntake = 1;

public void init() {

//Hint button event listener
butHint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

C# variables and classes

This quiz contains questions about C# classes and variables.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.