This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I'm sure that this question has been asked before, but none of the answers I have found so far have matched exactly what I am looking for. I am making a simple tic-tac-toe game, and I want to be able to set the icon of a button when it is clicked, but what the icon is depends on what the player's piece is. For instance, if the player is "X," then it will make the button have an "X." Most solutions I have found involve using setPressedIcon() and then adding the button to the panel with that information, but I cannot set the pressed icon until after the buttons have already been created and added to the board. Also, the computer must be able to change the icon of a button to the opposing letter. Can anyone help me find a way to do this?
And as for picking what icon to use, have a boolean state variable called turn. One player's turn is true and one player's turn is false. Whenever a button is clicked and it is given an icon, change the turn: turn = !turn;