0

I have a grid of buttons, displayed on a stage. Setting and getting the color of the buttons is behaving strangely.

int X=0;
int Y=0;
buttons[X][Y].setColor(Color.BLUE);  //this works, the button displays blue
boolean test = (buttons[X][Y].getColor()==Color.BLUE);
System.out.println(test);  //prints 'false' , why???
System.out.println(buttons[X][Y].getColor()); //prints '0000ffff'
System.out.println(Color.BLUE); //prints '0000ffff'

I need to be able to set and get the color of the buttons for the game I'm creating. Does anyone know what is going on and what I could do?

1 Answers1

0

The Color objects are different, but they have the same value. So, the objects may not be == equal but will be .equal() equal. See What is the difference between == vs equals() in Java?

Community
  • 1
  • 1
P.T.
  • 24,557
  • 7
  • 64
  • 95