I was trying something in my cs lecture then suddenly i have experienced an interesting problem.
this is my main code,
public void run(){
setSize(800, 600);
for(int i=0; i<= 30; i++){
elips el = new elips();
el.setFilled(true);
el.setColor(Color.RED);
elipsler.add(el);
add(el);
}
while(!stopthat){
for(int i=0; i< elipsler.size() -1; i++){
elipsler.get(i).cdRemove();
println("asd");
if(elipsler.get(i).canRemove == true){
remove(elipsler.get(i));
elipsler.remove(i);
elips el = new elips();
el.setFilled(true);
add(el);
elipsler.add(el);
}
}
}
}
and that's my ellipse class.
public class elips extends GOval{
static int x, y, w, h;
int cd;
public boolean canRemove = false;
Random rand = new Random();
public elips(){
super(x, y, w, h);
canRemove = false;
cd = rand.nextInt(100);
x = rand.nextInt(780) + 20;
y = rand.nextInt(580) + 20;
w = rand.nextInt(80) + 20;
h = rand.nextInt(80) + 20;
}
public void cdRemove(){
if(this.cd <= 0){
this.canRemove = true;
}else{
this.cd--;
}
}
}
As you see, I am creating ellipses and giving them "remove cooldown" and after end of cooldown the ellipses destroy. The problem is if i remove println("asd") line, code does not work properly. That is, if i remove that line, the ellipses appear and disappear at the same time(cooldowns don't work).
so I wonder how "println" line can solve this problem?