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

  • Home
  • SEARCH
  • 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 7872683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:16:47+00:00 2026-06-03T02:16:47+00:00

I am making a board game and having trouble moving them. The piece will

  • 0

I am making a board game and having trouble moving them. The piece will move according to the dice result. Below is what i attempt to do but it does not work.(from button[].addActionListener(new ActionListener()) Note: I have used ImageIcon to represent my pieces. Any help?

    //Puts the player 1 piece on button 1,3,5,7,9 and player 2 piece on button 2,4,6,8,10 
    if ((btnNumber - 1) < 10) 
    { 
        if (((btnNumber - 1) % 2) == 0) 
        { 
            buttons[btnNumber - 1].setIcon(piece1); 
        } 
        else 
        { 
            buttons[btnNumber - 1].setIcon(piece2); 
        } 
    } 
    centerPanel.add(buttons[btnNumber - 1]); 
} 

frame.add(centerPanel, BorderLayout.CENTER); 
  • 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-06-03T02:16:48+00:00Added an answer on June 3, 2026 at 2:16 am

    It looks as though there are some basic things you haven’t quite grasped yet. Here are some suggestions for getting closer to your goal:

    1. button[].addActionListener is a nonsensical statement. You can’t add an action listener to an entire array at once. Perhaps you meant to say buttons[btnNumber - 1].addActionListener and place it inside the for loop.
    2. buttons[]==ImageIcon("piece1") is also a meaningless statement (it should not even have compiled). You could try buttons[btnNumber - 1] == ImageIcon("piece1"), though there is an easier way to do this (#3).
    3. Instead of determining the location of the piece based on whether it equals an image icon instance, why not have variables piece1Location and piece2Location that you keep updated as the pieces move. Then you would know instantly where the pieces are, and your logic would simplify to if (btnNumber - 1 == piece1Location)
    4. In Java, arrays start at index 0. The cleanest way to work with an array in Java with a for loop is to start your indexing variable at 0 as well, and change your comparison from <= to <. With the following for(int i = 0; i < 30; i++), you don’t have to keep saying btnNumber - 1.
    5. The organization of your code is a little confusing and tightly integrated between model and presentation. You should seek to separate logic dealing with showing the board and pieces (presentation) from logic dealing with the mechanics of the game (rolling dice, moving pieces, etc.). This will help you immensely in maintaining your code and keeping track of what’s going on.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on making a board game for chess and checkers (and a few
I'm just getting started on making a board game using Cocoa/Objective-C. My plan is
I'm making Pacman game in opengl and I want to move my pacman in
I'm making an Online game where I will host a game server. Players will
I'm in the process of making a board game in Flash; as part of
I'm making a game with Python->PyGame->Albow and ran into a problem with board generation.
I am making a game board through a 2D char array and I want
Hey everybody I'm making a memory game where it's a 4x4 board and you
I am making a board game and I need to put the player 1
I am making a board game and I need to action a button which

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.