in java the operand to test equality between two items is == not '=' which is an assignment; an assignment returns the assigned value, so your :
if (playerOne = true)
will always be true as playerOne will be assigned to true
, then the if will become if (true)
and the statement associated will always be executed.
the best way to refactor your code is:
public void mouseClicked(MouseEvent arg0) {
if(playerOne) {
playerOne = false;
playerTwo = true;
boxOne.setIcon(xIcon);
} else if(playerTwo) {
playerOne = true;
playerTwo = false;
boxOne.setIcon(oIcon);
}
}
as the something == true
would be redundant.