I am creating a program that allows you to create a pie chart easily. In the method for removing a slice the if statement inside of a for loop doesnt execute and I cant figure out why this happens. Here is the removeSlice method:
public void removeSlice(Color color, float size, String displayText){
int num = 0;
System.out.println("Thing: " + color + " " + size + " " + displayText);
for(int i = 0; i < slice.size(); i++){
System.out.println("I: " + slice.get(i).color + " " + slice.get(i).size + " " + slice.get(i).text + " Current: " + i);
if(slice.get(i).color == color && slice.get(i).size == size && slice.get(i).text.equals(displayText)){
num = i;
System.out.println("It Works");
}
}
System.out.println(num);
slice.remove(slice.get(num));
totalSize -= size;
--current;
}
When trying to remove a slice the console output shows this
Thing: java.awt.Color[r=255,g=255,b=255] 100.0 Hey
I: java.awt.Color[r=0,g=0,b=0] 500.0 Hi Current: 0
I: java.awt.Color[r=255,g=153,b=153] 70.0 Hello Current: 1
I: java.awt.Color[r=255,g=255,b=255] 100.0 Hey Current: 2
I: java.awt.Color[r=153,g=153,b=0] 120.0 Hola Current: 3
0
as you see all of the values equal position 2's values in the ArrayList but still the if statement doesn't execute.