Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:33:35+00:00 2026-05-30T17:33:35+00:00

I am attempting to make a memory card matching game known as Concentration. So

  • 0

I am attempting to make a memory card matching game known as Concentration. So far I have 3 classes.
Memory extends JFrame implements ActionListener

Board extends JPanel implements ActionListener

Cell extends JButton

I have so far achieved a window to pop up. Use a list to add pairs of types of Cells. Distribute all the Cells randomly across my Board. Display the back (an img) of all Cells (there are 24 Cells, 4 rows 6 columns). Now when I click on my card I get a white image. At the moment as a short term goal, all I am trying to achieve is that when I click on a Button, the appropriate image shows up on the button.

I implemented ActionPerformed in this way, in the class Board.

 public void actionPerformed(ActionEvent e){

      if(e.getSource() instanceof Cell){

        Cell temp = (Cell)e.getSource();

        temp.setSelected(true);

        if (temp.selected()){

          int row = temp.getRow();
          int column = temp.getColumn();

          board[row][column].setIcon2();


        }
        }}

My set selected methods only serves to change the value of a boolean variable in the Cell class to true.
This is my setIcon2 method in the class Cell.

public void setIcon2(){
   ImageIcon x = new ImageIcon();


   x = getImageIcon();


    setIcon(x);
  }

Here is the getImageIcon method in the class Cell.

private ImageIcon getImageIcon() {
    int temp=0;
    int id;
    if (localSelected) { 

    id = getType();

    String tempId = Integer.toString(id);    

    icons[temp] = new ImageIcon("img-" + tempId + ".jpg");
    temp++;

    return icons[temp];
} else {

     id = IMAGE_NUMBER; 
     String strId = Integer.toString(id);
     icons[id] = new ImageIcon("img-" + strId + ".jpg");

 }

     return icons[id];
    }

There are no compilation errors or warnings of any sort. The getType method returns an integer variable associated to a value stored in my game board. (2D array of type Cell).

Tried to explain my predicament as clearly as possible, any sort of direction will be highly appreciated and valued.
Thank you
Mjall2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:33:37+00:00Added an answer on May 30, 2026 at 5:33 pm

    Use a JToggleButton. More specifically, use the setIcon and setSelectedIcon methods. Using this approach, you’ll avoid reinventing the wheel.

    EXAMPLE –

    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    import javax.swing.JToggleButton;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    
    final class JToggleButtonDemo {
        public static final void main(final String[] args) {
            SwingUtilities.invokeLater(new Runnable(){
                @Override
                public void run() {
                    createAndShowGUI();
                }
            });
        }
        private static final void createAndShowGUI(){
            final JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setLayout(new FlowLayout()); // For presentation purposes only.
            final JToggleButton button = new JToggleButton(UIManager.getIcon("OptionPane.informationIcon"));
            button.setSelectedIcon(UIManager.getIcon("OptionPane.errorIcon"));
            frame.add(button);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    }
    

    The toggle button in this example will show an information icon when unselected and an error icon when selected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was attempting to make a simple pokemon text game in c++. I created
I am attempting to make a full scale game for the first time and
I'm attempting to make a tank game in java in the vein of Scorched
I'm attempting to make a site beautiful, and so far it's gone quite well,
I'm attempting to make a simple game of Pairs for Android. Program Structure Menu.java
I am attempting to make a Facebook game and trying to replicate a common
I am attempting to make my GUI app have a CLI frontend (not the
I have a game I am attempting to program but the initial data entry
While attempting to make a game using Canvas I noticed a few quirks on
Attempting to make a NSObject called 'Person' that will hold the login details for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.