hey there,
I have two pieces of code that I expected would behave the same. However, what I noticed is that one of them works fine, the other does not at all. I need help from someone experienced to explain what's going on under the hood. the code that does not work at all is the following:
public void paintComponent(Graphics g){
g.setColor(Color.white);
g.fillRect(0, 0, 500, 500);
g.setColor(Color.black);
while(size>0){
Vizatuesi(size, g);
//size = (int)(size*0.8);
}
}
public void Vizatuesi(int size, Graphics g){
//while(size>0){
g.drawRect(0, 0, size, size);
size = (int)(size*0.8);
//}
and the code that does work, is the following:
public void paintComponent(Graphics g){
g.setColor(Color.white);
g.fillRect(0, 0, 500, 500);
g.setColor(Color.black);
while(size>0){
Vizatuesi(size, g);
size = (int)(size*0.8);
}
}
public void Vizatuesi(int size, Graphics g){
g.drawRect(0, 0, size, size);
}
to facilitate your analysis, note that my variable size, in the code that works is being reduced in the paintComponent method, whereas it is being reduced inside the helper method Vizatuesi() in the code that does not work.
any insight is much appreciated