In my processing program, I added an object into a global ArrayList called items in my draw function.
Here is the class.
class Obj {
String name;
Obj(String name) {
self.name = name;
}
}
Here is my draw function.
void draw () {
items.add(new Obj("Bob"));
}
I tried printing the size of items in my mouseClicked() function into the console, but I keep getting 0.
void mouseClicked () {
print(items.size());
}
Why?
The ArrayList is declared at the top of my file after my class:
ArrayList<Obj> items = new ArrayList<Obj>();
There are a couple of things which aren’t quite there yet:
self.name = name;should bethis.name = name;mouseCliked()(also you might want to useprintln()instead).Try this: