Question

Introduction to Java Programming Question: I’m doing a java game which user clicks on two different...

Introduction to Java Programming Question:

I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically looking for codes that could make my memory match game more difficult or more interesting.(a timer, difficulty level, color, etc.) GUI must be included in the code.

Here is what I got so far:

package Card;

import javax.swing.JButton;

public class Card extends JButton{

   private int id;

   private boolean matched = false;

   public void setId(int id){

   this.id = id;

   }

   public int getId(){

   return this.id;

   }

   public void setMatched(boolean matched){

   this.matched = matched;

   }

   public boolean getMatched(){

   return this.matched;

   }

}

package Card;

import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.Timer;

import java.awt.*;

import java.awt.event.*;

import java.util.ArrayList;

import java.util.List;

import java.util.Collections;

public class Board extends JFrame{

   private List cards;

private Card selectedCard;

private Card c1;

private Card c2;

private Timer t;

public Board(){

int pairs = 10;

List cardsList = new ArrayList();

List cardVals = new ArrayList();

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

cardVals.add(i);

cardVals.add(i);

}

Collections.shuffle(cardVals);

for (int val : cardVals){

Card c = new Card();

c.setId(val);

c.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent ae){

selectedCard = c;

doTurn();

}

});

cardsList.add(c);

}

this.cards = cardsList;

//set up the timer

t = new Timer(750, new ActionListener(){

public void actionPerformed(ActionEvent ae){

checkCards();

}

});

t.setRepeats(false);

//set up the board itself

Container pane = getContentPane();

pane.setLayout(new GridLayout(4, 5));

for (Card c : cards){

pane.add(c);

}

setTitle("Memory Match");

}

public void doTurn(){

if (c1 == null && c2 == null){

c1 = selectedCard;

c1.setText(String.valueOf(c1.getId()));

}

if (c1 != null && c1 != selectedCard && c2 == null){

c2 = selectedCard;

c2.setText(String.valueOf(c2.getId()));

t.start();

}

}

public void checkCards(){

if (c1.getId() == c2.getId()){//match condition

c1.setEnabled(false); //disables the button

c2.setEnabled(false);

c1.setMatched(true); //flags the button as having been matched

c2.setMatched(true);

if (this.isGameWon()){

JOptionPane.showMessageDialog(this, "You win!");

System.exit(0);

}

}

else{

c1.setText(""); //'hides' text

c2.setText("");

}

c1 = null;

c2 = null;

}

public boolean isGameWon(){

for(Card c: this.cards){

if (c.getMatched() == false){

return false;

}

}

return true;

}

}

package Card;

import java.awt.Dimension;

import javax.swing.JFrame;

public class Game{

   public static void main(String[] args){

   Board b = new Board();

   b.setPreferredSize(new Dimension(500,500));

   b.setLocation(500, 250);

   b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   b.pack();

   b.setVisible(true);

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.Timer;

/
public class Board extends JPanel implements ActionListener {

////////////////////////////////////////////////////////////////////////////
// Constants
////////////////////////////////////////////////////////////////////////////

private static final String TAG = "Board: ";

// Serial ID
private static final long serialVersionUID = 1L;
// Logic constants
private static final int BOARD_BORDER_WIDTH = 20;
private static final int MAX_NUM_OF_CARDS = 24;
private static final int MIN_NUM_OF_CARDS = 1;
private static final int NUMBER_OF_ROWS = 4;
private static final int NUMBER_OF_COLUMNS = 6;
private static final int NUMBER_OF_PAIRS = 12;

private static final int MAX_SELECTED_CARDS = 2;
private static final int FIRST = 0;
private static final int SECOND = 1;
private static final int VISIBLE_DELAY = (int) 2 * 1000;
private static final int PEEK_DELAY = (int) 2 * 1000;

// Card types
private static final int EMPTY_CELL_TYPE = 0;
private static final int HIDDEN_CARD_TYPE = 26;
private static final int EMPTY_CARD_TYPE = 25;

// Card image file properties
private static final String DEFAULT_IMAGE_FILENAME_SUFFIX = ".jpg";
private static final String DEFAULT_IMAGE_FILENAME_PREFIX = "img-";
private static final String DEFAULT_IMAGE_FOLDER = "/images/";
private static final String HIDDEN_IMAGE_PATH = DEFAULT_IMAGE_FOLDER
   + DEFAULT_IMAGE_FILENAME_PREFIX + "26"
   + DEFAULT_IMAGE_FILENAME_SUFFIX;
private static final String EMPTY_IMAGE_PATH = DEFAULT_IMAGE_FOLDER
   + DEFAULT_IMAGE_FILENAME_PREFIX + "25"
   + DEFAULT_IMAGE_FILENAME_SUFFIX;

////////////////////////////////////////////////////////////////////////////
// Static variables
////////////////////////////////////////////////////////////////////////////

private static ArrayList<Cell> chosenCards = new ArrayList<Cell>();
private static int numOfMatchedPairs = 0;
private static int numOfFailedAttempts = 0;
private static int selectedCards = 0;

////////////////////////////////////////////////////////////////////////////
// Instance variables
////////////////////////////////////////////////////////////////////////////

private Cell[][] mBoard = null;
private String[] mCardStorage = initCardStorage();
private Cell[] mCardChecker = new Cell[MAX_SELECTED_CARDS];

////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////
/**
* Initialize a Board ready to be used for a game.
*/
public Board() {
super();

setBackground(Color.WHITE);
setBorder(BorderFactory.createEmptyBorder(BOARD_BORDER_WIDTH,
    BOARD_BORDER_WIDTH, BOARD_BORDER_WIDTH, BOARD_BORDER_WIDTH));
setLayout(new GridLayout(NUMBER_OF_ROWS, NUMBER_OF_COLUMNS));

mBoard = new Cell[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS];

for (int row = 0; row < NUMBER_OF_ROWS; row++) {
   for (int column = 0; column < NUMBER_OF_COLUMNS; column++) {
    mBoard[row][column] = new Cell(EMPTY_CELL_TYPE);
    mBoard[row][column].addActionListener(this);
    add(mBoard[row][column]);
   }
}

init();
}

////////////////////////////////////////////////////////////////////////////
// Public Interface
////////////////////////////////////////////////////////////////////////////

/**
* This method initializes the board with a new set of cards
*/
public void init() {

resetMatchedImages();
resetBoardParam();
peek();
mCardStorage = initCardStorage();
setImages();

}

/**
* This method reinitializes the board with the current set of cards i.e.
* replay
*/
public void reInit() {

resetMatchedImages();
resetBoardParam();
peek();
setImages();

}

/**
* This method checks if the board is solved or not.
*
* @return true if the board is solved, false if there remains cards that
*         have to be matched
*/
public boolean isSolved() {

// No check for null, the method can't be called out of
// an instance, and the constructor initialize the mBoard

for (int row = 0; row < NUMBER_OF_ROWS; row++) {
   for (int column = 0; column < NUMBER_OF_COLUMNS; column++) {
    if (!mBoard[row][column].isEmpty()) {
     return false;
    }
   } // column loop
} // row loop

return true;
}

/**
* This method adds a selected card to the chosen card list
*
* @param aCard
*            is the card to be added to the list
*/

private void addToChose(Cell aCard) {

if (aCard != null) {
   if (!chosenCards.contains(aCard)) {
    chosenCards.add(aCard);
   }
} else {
   error("addToChose( Cell ) received null.", true);
}

}

/**
* This method is the action performed when a card is clicked it represents
* the main user interface of the game
*
* @param e
*            an ActionEvent
*/
public void actionPerformed(ActionEvent e) {

if (e == null) {
   error("actionPermormed(ActionEvent) received null", false);
   return;
}

// Flush out cases where we don't care
if (!(e.getSource() instanceof Cell)) {
   return;
}

if (!isCardValid((Cell) e.getSource())) {
   return;
}

// Proceed with cases we want to cover

++selectedCards;

if (selectedCards <= MAX_SELECTED_CARDS) {
   Point gridLoc = getCellLocation((Cell) e.getSource());
   setCardToVisible(gridLoc.x, gridLoc.y);
   mCardChecker[selectedCards - 1] = getCellAtLoc(gridLoc);
   addToChose(getCellAtLoc(gridLoc));
}

if (selectedCards == MAX_SELECTED_CARDS) {

   if (!sameCellPosition(mCardChecker[FIRST].getLocation(),
     mCardChecker[SECOND].getLocation())) {

    setSelectedCards(mCardChecker[FIRST], mCardChecker[SECOND]);
   } else {
    --selectedCards;
   }
} // if selectedCards == MAX
}

////////////////////////////////////////////////////////////////////////////
// Utils Methods
////////////////////////////////////////////////////////////////////////////

// This method returns the location of a Cell object on the board
private Cell getCellAtLoc(Point point) {
if (point == null) {
   error("getCellAtLoc( Point ) received null", true);
   return null;
}

return mBoard[point.x][point.y];
}

// This method sets a card to visible at a certain location
private void setCardToVisible(int x, int y) {

mBoard[x][y].setSelected(true);
showCardImages();
}

// This method delays the setCards method, so the user can peek at the cards
// before the board resets them
private void peek() {

Action showImagesAction = new AbstractAction() {

   private static final long serialVersionUID = 1L;

   public void actionPerformed(ActionEvent e) {
    showCardImages();
   }
};

Timer timer = new Timer(PEEK_DELAY, showImagesAction);
timer.setRepeats(false);
timer.start();
}

// This method sets the images on the board
private void setImages() {

ImageIcon anImage;

for (int row = 0; row < NUMBER_OF_ROWS; row++) {
   for (int column = 0; column < NUMBER_OF_COLUMNS; column++) {

    URL file = getClass().getResource(
      DEFAULT_IMAGE_FOLDER
        + DEFAULT_IMAGE_FILENAME_PREFIX
        + mCardStorage[column
          + (NUMBER_OF_COLUMNS * row)]
        + DEFAULT_IMAGE_FILENAME_SUFFIX);

    if (file == null) {
     System.err.println(TAG
       + "setImages() reported error \"File not found\".");
     System.exit(-1);
    }

    anImage = new ImageIcon(file);

    mBoard[row][column].setIcon(anImage);

   } // column loop
} // row loop
}

// This method shows a specific image at a certain location
private void showImage(int x, int y) {

URL file = getClass().getResource(
    DEFAULT_IMAGE_FOLDER + DEFAULT_IMAGE_FILENAME_PREFIX
      + mCardStorage[y + (NUMBER_OF_COLUMNS * x)]
      + DEFAULT_IMAGE_FILENAME_SUFFIX);

if (file == null) {
   System.err.println(TAG
     + "showImage(int, int) reported error \"File not found\".");
   System.exit(-1);
}

ImageIcon anImage = new ImageIcon(file);
mBoard[x][y].setIcon(anImage);

}

// This method sets all the images on the board
private void showCardImages() {

// For each card on the board
for (int row = 0; row < NUMBER_OF_ROWS; row++) {
   for (int column = 0; column < NUMBER_OF_COLUMNS; column++) {

    // Is card selected ?
    if (!mBoard[row][column].isSelected()) {

     // If selected, verify if the card was matched by the user
     if (mBoard[row][column].isMatched()) {
      // It was matched, empty the card slot
      mBoard[row][column].setIcon(new ImageIcon(getClass()
        .getResource(EMPTY_IMAGE_PATH)));
      mBoard[row][column].setType(EMPTY_CARD_TYPE);
     } else {
      // It was not, put the "hidden card" image
      mBoard[row][column].setIcon(new ImageIcon(getClass()
        .getResource(HIDDEN_IMAGE_PATH)));
      mBoard[row][column].setType(HIDDEN_CARD_TYPE);
     }

    } else {
     // The card was not selected
     showImage(row, column);

     String type = mCardStorage[column
       + (NUMBER_OF_COLUMNS * row)];
     int parsedType = Integer.parseInt(type);

     mBoard[row][column].setType(parsedType);

    } // Is card selected?
   } // inner loop - columns
} // outer loop - rows
}

// This method generates a random image, i.e. a random integer representing
// the type of the image

private String generateRandomImageFilename(int max, int min) {

Random random = new Random();
Integer aNumber = (min + random.nextInt(max));

if (aNumber > 0 && aNumber < 10) {
   return "0" + aNumber;
} else {
   return aNumber.toString();
}
}

// This method creates an array of string holding the indices of 24 random
// images grouped in pairs.

private String[] initCardStorage() {

String[] cardStorage = new String[MAX_NUM_OF_CARDS];
String[] firstPair = new String[NUMBER_OF_PAIRS];
String[] secondPair = new String[NUMBER_OF_PAIRS];

firstPair = randomListWithoutRep();

for (int i = 0; i < NUMBER_OF_PAIRS; i++) {
   cardStorage[i] = firstPair[i];
}

Collections.shuffle(Arrays.asList(firstPair));

for (int j = 0; j < NUMBER_OF_PAIRS; j++) {
   secondPair[j] = firstPair[j];
}

for (int k = NUMBER_OF_PAIRS; k < MAX_NUM_OF_CARDS; k++) {
   cardStorage[k] = secondPair[k - NUMBER_OF_PAIRS];
}

return cardStorage;
}

// this method is to generate a list of NUMBER_OF_PAIRS images (types)
// without repetition

private String[] randomListWithoutRep() {

String[] generatedArray = new String[NUMBER_OF_PAIRS];
ArrayList<String> generated = new ArrayList<String>();

for (int i = 0; i < NUMBER_OF_PAIRS; i++) {
   while (true) {
    String next = generateRandomImageFilename(MAX_NUM_OF_CARDS,
      MIN_NUM_OF_CARDS);

    if (!generated.contains(next)) {
     generated.add(next);
     generatedArray[i] = generated.get(i);
     break; // breaks back to "for" loop
    }
   } // inner loop - for every random card, ensure its not already
    // existing
} // outer loop - we want NUMBER_OF_PAIRS different pairs

return generatedArray;
}

// This method gets the location of a cell on the board and returns that
// specific point
private Point getCellLocation(Cell aCell) {

if (aCell == null) {
   error("getCellLocation(Cell) received null", true);
   return null;
}

Point p = new Point();

for (int column = 0; column < NUMBER_OF_ROWS; column++) {

   for (int row = 0; row < NUMBER_OF_COLUMNS; row++) {

    if (mBoard[column][row] == aCell) {
     p.setLocation(column, row);
     return p;
    }
   } // row for
} // column for
return null;
}

// This methods checks if 2 cards are the same
private boolean sameCellPosition(Point firstCell, Point secondCell) {

if (firstCell == null || secondCell == null) {
   if (secondCell == firstCell) {
    // They're equal if both are null
    return true;
   }

   if (firstCell == null) {
    error("sameCellPosition(Point, Point) received (null, ??)",
      true);
   }
   if (secondCell == null) {
    error("sameCellPosition(Point, Point) received (??, null)",
      true);
   }

   return false;
}

if (firstCell.equals(secondCell)) {
   return true;
}
return false;
}

// This method check if any 2 selected cards are the same so it replaces
// them with a blank cell or if they're different it flips them back,
// it also check if the board is solved
private void setSelectedCards(Cell firstCell, Cell secondCell) {

if (firstCell == null || secondCell == null) {

   if (firstCell == null) {
    error("setSelectedCards(Cell, Cell) received (null, ??)", true);
   }
   if (secondCell == null) {
    error("setSelectedCards(Cell, Cell) received (??, null)", true);
   }
   return;
}

if (firstCell.sameType(secondCell)) {

   firstCell.setMatched(true);
   secondCell.setMatched(true);
   firstCell.setSelected(false);
   secondCell.setSelected(false);
   showImage(getCellLocation(secondCell).x,
     getCellLocation(secondCell).y);
   peek();
   numOfMatchedPairs++;
   finalMessage();
} else {

   firstCell.setMatched(false);
   secondCell.setMatched(false);
   firstCell.setSelected(false);
   secondCell.setSelected(false);
   showImage(getCellLocation(secondCell).x,
     getCellLocation(secondCell).y);
   peek();
   numOfFailedAttempts++;
}
resetSelectedCards();
}

// This method checks if a selected card is valid, the user isn't allowed to
// select blank cells again
private boolean isCardValid(Cell aCard) {

if (aCard == null) {
   error("isCardValid(Cell) received null", false);
   return false;
}

if (!aCard.isEmpty()) {
   return true;
} else {
   return false;
}

}

// This method displays the results when the game is solved
private void finalMessage() {

@SuppressWarnings("serial")
// Anonymous class are not to be serialized
Action showImagesAction = new AbstractAction() {

   public void actionPerformed(ActionEvent e) {
    if (isSolved()) {

     Float numeralScore = (((float) numOfFailedAttempts) / ((float) MAX_NUM_OF_CARDS)) * 100;
     String textualScore = numeralScore.toString();

     JOptionPane.showMessageDialog(null,
       "Solved!! Your results:\n" + " Failed Attempts: "
         + numOfFailedAttempts
         + "\n Error percentage : " + textualScore
         + " %", "RESULTS",
       JOptionPane.INFORMATION_MESSAGE);
    } // if solved
   } // actionPerformed()
}; // class implementation

Timer timer = new Timer(VISIBLE_DELAY, showImagesAction);
timer.setRepeats(false);
timer.start();

}

// this method resets all the matched images, used in the replay method and
// new game
private void resetMatchedImages() {
for (int row = 0; row < NUMBER_OF_ROWS; row++) {
   for (int column = 0; column < NUMBER_OF_COLUMNS; column++) {
    if (mBoard[row][column].isMatched()) {
     mBoard[row][column].setMatched(false);
    } // if
   } // for column
} // for row
}

////////////////////////////////////////////////////////////////////////////
// Static methods
////////////////////////////////////////////////////////////////////////////

/**
* Error reporting.
*/
private static void error(String message, boolean crash) {
System.err.println(TAG + message);
if (crash) {
   System.exit(-1);
}
}

// This method resets the number of selected cards to 0 after 2 cards have
// been chosen and checked
private static void resetSelectedCards() {
selectedCards = 0;
}

// This method resets the number of matched pairs on the board
private static void resetNumMatchedCards() {
numOfMatchedPairs = 0;
}

// This method resets the number of failed attempts
private static void resetFailedAttempts() {
numOfFailedAttempts = 0;
}

// This method resets the parameters of the board
// used when replaying or when starting a new game
private static void resetBoardParam() {

resetFailedAttempts();
resetNumMatchedCards();
}

}

import javax.swing.JButton;


public class Cell extends JButton {

////////////////////////////////////////////////////////////////////////////
// Constant
////////////////////////////////////////////////////////////////////////////

// Debug
private static final String TAG = "Cell: ";

// Serial
private static final long serialVersionUID = 1L;

// Cell types
private static final int MAX_TYPE_RANGE = 26;
private static final int MIN_TYPE_RANGE = 0;
private static final int EMPTY_CELL_TYPE = 25;

////////////////////////////////////////////////////////////////////////////
// Instance variables
////////////////////////////////////////////////////////////////////////////
private boolean mIsSelected = false;
private boolean mIsMatched = false;
private int mType = EMPTY_CELL_TYPE;

////////////////////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////////////////////

/**
* Creates a cell of the specified type.
*/
public Cell(int aType) {
super();
mType = aType;
}

////////////////////////////////////////////////////////////////////////////
// Public Interface
////////////////////////////////////////////////////////////////////////////

/**
* This method gets the type of the cell
*
* @return an int value that represents a specific
* card, an empty cell place or a card that is currently hidden.
*/
public int getType() {

return mType;
}

/**
* Sets the type of this cell. The range is between MIN_TYPE_RANGE
* and MAX_TYPE_RANGE
* @param aType is a valid integer value. An invalid value
* means something is wrong with the caller, and therefore the
* program will stop with an error.
*/
public void setType(int aType) {
if (aType > MAX_TYPE_RANGE || aType < MIN_TYPE_RANGE){
   error("setType(int) reported \"Invalid type code\"", true);
}
mType = aType;
}

/**
* This method checks if 2 cells are of the same type
*
* @param other is the second Cell we want to be compared to
* @return true if the given Cell shares the same image,
* false if the Cells are not related.
*/
public boolean sameType(Cell other) {

if (other == null) {
   error("sameType(Cell) received null", false);
   return false;
}

if (this.getType() == other.getType()) {
   return true;
} else {
   return false;
}
}

/**
* This method checks if the type of this cell is empty (blank cell)
*
* @return true if this cell is considered empty, false
* if this cell has not yet been paired with another cell
*/
public boolean isEmpty() {
if (this.mType != EMPTY_CELL_TYPE) {
   return false;
}
return true;
}

/**
* This method set the cell to selected
* @param selected tells this cell that it is currently under selection
* by a player
*/
public void setSelected(boolean selected) {

mIsSelected = selected;
}

/**
* This method sets the cell to matched
*
* @param matched tells this cell that it has been matched with its
* sister cell by the player.
*/
public void setMatched(boolean matched) {

mIsMatched = matched;
}

/**
* This method checks if a cell is selected
*
* @return true if the user is currently selecting this cell,
* false if the cell has not been selected
*/
public boolean isSelected() {

if (mIsSelected == true) {
   return true;
}

return false;
}

/**
* This method checks if a cell is matched
*
* @return true if the cell was previously paired with its sister cell,
* false if it has yet to be paired by the player
*/
public boolean isMatched() {

if (mIsMatched == true) {
   return true;
} else {
   return false;
}
}

////////////////////////////////////////////////////////////////////////////
// Static methods
////////////////////////////////////////////////////////////////////////////

/**
* Error reporting.
*/
private static void error( String message, boolean crash ){
System.err.println( TAG + message );
if (crash) System.exit(-1);
}

}

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JSplitPane;


public class Memory extends JFrame {

///////////////////////////////////////////////////////////////////////////
// Constants
///////////////////////////////////////////////////////////////////////////

private static final long serialVersionUID = 1L;

///////////////////////////////////////////////////////////////////////////
// Instance variables
///////////////////////////////////////////////////////////////////////////

// Logic
private Board mBoard;
// GUI components
private JButton mRetryButton;
private JButton mNewButton;
private JSplitPane mSplitPane;

///////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////

/**
* Creates a Frame to start and display the game to the user.
*/
public Memory() {

super();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBackground(Color.WHITE);

mBoard = new Board();
add(mBoard, BorderLayout.CENTER);

mSplitPane = new JSplitPane();
add(mSplitPane, BorderLayout.SOUTH);

mRetryButton = new JButton("Retry");
mRetryButton.setFocusPainted(false);
mRetryButton.addMouseListener(btnMouseListener);
mSplitPane.setLeftComponent(mRetryButton);

mNewButton = new JButton("New Game");
mNewButton.setFocusPainted(false);
mNewButton.addMouseListener(btnMouseListener);
mSplitPane.setRightComponent(mNewButton);

pack();
setResizable(true);
setVisible(true);

}

///////////////////////////////////////////////////////////////////////////
// Listeners
///////////////////////////////////////////////////////////////////////////

private MouseListener btnMouseListener = new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
   if (e.getClickCount() == 1 && e.getComponent() == mRetryButton) {
    mBoard.reInit();
   } else if (e.getClickCount() == 1 && e.getComponent() == mNewButton) {
    mBoard.init();
   }
}
};

///////////////////////////////////////////////////////////////////////////
// Static methods
///////////////////////////////////////////////////////////////////////////

/**
* Starts the game. You need to have a running windows server/system to use
* this application. It is not compatible with CLI.
*
* @param args
*            - Parameters are ignored.
*/
public static void main(String[] args) {
new Memory();
}
}

Add a comment
Know the answer?
Add Answer to:
Introduction to Java Programming Question: I’m doing a java game which user clicks on two different...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Introduction to Java Programming Question: I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically look...

    Introduction to Java Programming Question: I’m doing a java game which user clicks on two different blocks and see the number and remember their locations and match the same number. I’m basically looking for codes that could make my memory match game more difficult or more interesting.(a timer, difficulty level, color, etc.) GUI must be included in the code. Here is what I got so far: package Card; import javax.swing.JButton; public class Card extends JButton{    private int id;    private boolean...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • Can you help me to link two frames in Java Swing and then if you click...

    Can you help me to link two frames in Java Swing and then if you click "Proceed button" it will link to the Second Frame...Thank you :) First frame code: //First import javax.swing.*; import java.awt.event.*; import java.io.*; public class Sample extends JFrame implements ActionListener { JMenuBar mb; JMenu file; JMenuItem open; JTextArea ta; JButton proceed= new JButton("Proceed"); Sample() { open = new JMenuItem("Open File"); open.addActionListener(this); file = new JMenu("File"); file.add(open); mb = new JMenuBar(); mb.setBounds(0, 0, 400, 20); mb.add(file); ta...

  • Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button...

    Modify Java Code below: - Remove Button Try the Number -Instead of Try the Number button just hit enter on keyboard to try number -Remove Button Quit import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Random; // Main Class public class GuessGame extends JFrame { // Declare class variables private static final long serialVersionUID = 1L; public static Object prompt1; private JTextField userInput; private JLabel comment = new JLabel(" "); private JLabel comment2 = new JLabel(" "); private int...

  • In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show...

    In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...

  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • Hi! I'm working on building a GUI that makes cars race across the screen. So far...

    Hi! I'm working on building a GUI that makes cars race across the screen. So far my code produces three cars, and they each show up without error, but do not move across the screen. Can someone point me in the right direction? Thank you! CarComponent.java package p5; import java.awt.*; import java.util.*; import javax.swing.*; @SuppressWarnings("serial") public class CarComponent extends JComponent { private ArrayList<Car> cars; public CarComponent() { cars = new ArrayList<Car>(); } public void add(Car car) { cars.add(car); } public...

  • NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the...

    NETBEANS JAVA BANK PROGRAM (TAKE SCREENSHOTS FROM NETBEANS INCLUDING OUTPUT PLEASE) Display the accounts for the current displayed customer PLEASEEEEEEEEEE package bankexample; import java.util.UUID; public class Customer { private UUID id; private String email; private String password; private String firstName; private String lastName;    public Customer(String firstName, String lastName, String email, String password) { this.id = UUID.randomUUID(); this.firstName = firstName; this.lastName = lastName; this.email = email; this.password = password; } public String getFirstName() { return firstName; } public void setFirstName(String...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT