PDA

View Full Version : Color returned from .getColor is inconsistent


rfgrove
02-08-2010, 11:23 AM
I'm writing Java code to manipulate geometric shapes in Alice 3. The code sets the color of each shape. My expectation was that the method getColor() would return a reference to the Color constant that was used to set the color, but it returns a different object each time it's called. Can anyone explain what these different Color objects are and why they're not the same?

MyTriangle tri = new MyTriangle();
tri.setColor(Color.BLUE);
System.out.println(Color.BLUE);
for (int i=0; i<3; i++) {
System.out.println(tri.getColor());
}

org.alice.apis.moveandturn.Color@77eaf8
org.alice.apis.moveandturn.Color@e35bb7
org.alice.apis.moveandturn.Color@9a8a68
org.alice.apis.moveandturn.Color@1f4e571

jediaction
02-08-2010, 11:40 AM
I am not exactly sure but I have Alice 3 and you cannot have 2 objects the same. If this is in an if/else statement, it should work but also, you could have a little mess up in the code an it wont work. I have noticed that the code is messed up but im trying to figure out what is messed up...hold on, i dont udner stand line 4 of the code