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 7936357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:11:22+00:00 2026-06-03T22:11:22+00:00

Does anybody know how to refresh button Image Icons? The problem is: I’m making

  • 0

Does anybody know how to refresh button Image Icons?

The problem is:

I’m making a checkers game, and creating a GUI. Everything works including the AI, except that I called my AI after I placed a move, resulting the buttons does not appear to have checker on it.

  1. Clicked Button
  2. Click on a specific button where there is a checker
  3. Click on the the next spot where the checker has to go
  4. Immediately call the AI to make a move.

My buttons have ImageIcons of checkers pictures, when I click to the next spot where the checker needs to go, the JButton on the JPanel does not refresh at that instant, but waiting until the AI to make the move and finish it’s move, resulting that I don’t see where my checker went.

When 3-4 Calls one after another, I only see the resulting move the AI did, but not mine, because everything refreshes after it exits the implements actionListener.

I tried calling:
repaint();
revalidate();
invalidate();
On the JPanel that contains the buttons.

before step 4 so that the user can see what he/she has placed before the AI making the move.

else
{
     //This is where the code starts
     if ("White".equals(Red_Or_White.getText()))
     {
          //Meaning that it is white's turn, then
          playerPlaysAMove(x, y, goingToGo_x, goingToGo_y);
     }
     if ("AI".equals(AI_Enabled.getText()))
     {
          //AI is enabled
          AIMoves(board, "Red");
          //the AI needs to play the position as if the AI was a red player, 
          //because the player must be white
     }
}

Both the AI plays on the same round, but AI calculations takes about 1 minute, and at that time, the player’s move is not visible until the AI plays, because it updates all of the buttons after going out of actionListener (after else statement).

Board is a array of 8×8 Buttons that is placed on a JPanel

static void playerPlaysAMove(int save_x, int save_y, int moveTo_x, int moveTo_y)
{
    if(save_x - moveTo_x == 1 || save_x - moveTo_x == -1)
    {
        board[moveTo_x][moveTo_y].setIcon(board[save_x][save_y].getIcon());
        board[save_x][save_y].setIcon(null);
    }
    else if (save_x - moveTo_x == 2 && save_y - moveTo_y == 2)
    {
        board[save_x-1][save_y-1].setIcon(null);
        board[moveTo_x][moveTo_y].setIcon(board[save_x][save_y].getIcon());
        board[save_x][save_y].setIcon(null);
    }
    else if (save_x - moveTo_x == 2 && save_y - moveTo_y == -2)
    {
        board[save_x-1][save_y+1].setIcon(null);
        board[moveTo_x][moveTo_y].setIcon(board[save_x][save_y].getIcon());
        board[save_x][save_y].setIcon(null);            
    }
    else if (save_x - moveTo_x == -2 && save_y - moveTo_y == 2)
    {
        board[save_x+1][save_y-1].setIcon(null);
        board[moveTo_x][moveTo_y].setIcon(board[save_x][save_y].getIcon());
        board[save_x][save_y].setIcon(null);            
    }
    else if (save_x - moveTo_x == -2 && save_y - moveTo_y == -2)
    {
        board[save_x+1][save_y+1].setIcon(null);
        board[moveTo_x][moveTo_y].setIcon(board[save_x][save_y].getIcon());
        board[save_x][save_y].setIcon(null);            
    }        
}

Basically is I calculated the X Y coordinate of the user’s select button, and the user’s destination button. There are some checking whether he is playing the correct move or not, but this is the major movement part.

If the X Y coordinate difference is 1, that means the player is moving, not jumping, if the X Y coordinate difference is 2, that means the player is jumping. I also need to set the original X Y coordinate’s button to null, that means the icon disappears, and then place the new imageIcon at the destination X Y coordinate.

If the player is jumping, then I also need to calculate the place where the user eats the piece, and set that imageIcon to be null also.

The AI does the exact same thing, except the AI calculates the X Y coordinate by using recursive functions to calculate the best move.

The Main problem is that the player players, and then AI computes, and plays, then after the process, it will show the result of both together. Is it possible to let it redraw the image icon before the AI computes and plays? So that the player can see what he played, and then what the AI played

  • 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-03T22:11:24+00:00Added an answer on June 3, 2026 at 10:11 pm

    Try with board[save_x][save_y].repaint();

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

Sidebar

Related Questions

Does anybody know, where I can find the original image-files (button backgrounds, menu icons,
does anybody know, where I can find the Google Calendars Event-GUI? I'm building an
Does anybody know a way to create a keyboard shortcut for the button 'Expand
Does anybody know the logic behind making DataSourceSelectArguments sealed? I've implemented a custom DataSource
Does anybody know of or have a detailed list of how the BCL in
Does anybody know, how to get a list of leaf nodes in Prolog? Let's
Does anybody know of a free flash obfuscator(protector)? All I can find are commercial
Does anybody know whether one exists? I've been googling this for monthes... Thanks
Does anybody know if you can access the SaevFileDialog control that's used by the
Does anybody know what is the equivalent to $? in Windows command line? Is

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.