please format code with </> button * homework policy * asking questions
Hello fellow processing members,
I am working on a project where Iam trying to make a program using an ArrayList.
The goal is to have a square at x:100 y:100 and being able to drag it to a new location, once I have dragged it to that new location the ArrayList has to add an object to the list and put a new square on the screen at x:100 y:100 to drag to a new location.
I know how to make the list and add objects, but I cant separate the object from each other. They stay in the same place.
Edit: I am new here sorry if I defined the code wrong wit the ā<>ā
my main code is looking like this so far:
int x = 100;
int y = 100;
int sz = 100;
boolean isGekozen;
ArrayList<Tegenstander> tegenstanders;
void setup(){
fullScreen();
background(0);
tegenstanders = new ArrayList<Tegenstander>();
tegenstanders.add(new Tegenstander());
}
void draw(){
background(0);
for (int i = tegenstanders.size() - 1; i >= 0; i--) {
Tegenstander t = tegenstanders.get(i);
t.display();
t.isGekozen();
}
println(tegenstanders.size());
}
The class:
class Tegenstander{
void display(){
fill(100);
rect(100, 100, sz, sz);
}
boolean isGekozen (){
fill(100);
rect(x, y, sz, sz);
if(mouseX> x && mouseX < x+100 && mouseY > y && mouseY < y+100){
cursor(HAND);
stroke(255);
if(mousePressed){
strokeWeight(5);
x = mouseX-50;
y = mouseY-50;
return true;
}
else{
strokeWeight(2);
return false;
}
}
else{
cursor(ARROW);
noStroke();
return false;
}
}
}