arraylist
in
Programming Questions
•
1 year ago
Hi,
An array list is a resizable list ob objects. I´ve used it sometimes but now I simply need a resizable list of variables. In this case of colors, and it doesnt work. It doesnt seem to me that the solution is to make a class of colors. I thougt that I could use an arraylist of colors and it doesnt work. This is the line of the errror:
colors.add (new color (c));
This is the complete code, trying to get a color palette from a picture
class ColorHandler {
color[] palette ;
ColorHandler(){
}
void SetColor(PImage theimage){
color c;
boolean found;
ArrayList colors = new ArrayList ();
for (int i = 0; i < theimage.width; i++){
for (int j = 0; j < theimage. height; j++){
c= theimage.get(i,j);
found = FALSE;
for ( k = 0; k < colors.size; k++){
color thecolor = (color) colors.get(k);
if (thecolor == c){
found = TRUE;
}
}
if (!found){
colors.add (new color (c));
}
}
}
}
}
color[] palette ;
ColorHandler(){
}
void SetColor(PImage theimage){
color c;
boolean found;
ArrayList colors = new ArrayList ();
for (int i = 0; i < theimage.width; i++){
for (int j = 0; j < theimage. height; j++){
c= theimage.get(i,j);
found = FALSE;
for ( k = 0; k < colors.size; k++){
color thecolor = (color) colors.get(k);
if (thecolor == c){
found = TRUE;
}
}
if (!found){
colors.add (new color (c));
}
}
}
}
}
1