I am trying to do this:

public void drawCircle(int x, int y, int diameter, int it) {
int d = diameter / 3;
if (it == 0) {
return;
}
g.setColor(Color.green);
g.fillOval(x, y, d, d);
drawCircle(x, y, d, it--);
drawCircle(x - d, y, d, it--);
drawCircle(x + d, y, d, it--);
}
For the purposes of this question, ignore the actual positions of those where I draw the circles - I will change this later, as this is not entirely correct. However, where am I mistaken in the logic of my program? It seems to me that I call the method of drawing three circles in each iteration. Here is my mistake:
Exception in thread "AWT-EventQueue-0" java.lang.StackOverflowError
at sun.java2d.loops.ProcessPath.ProcessMonotonicCubic(Unknown Source)
at sun.java2d.loops.ProcessPath.ProcessCubic(Unknown Source)
at sun.java2d.loops.ProcessPath.doProcessPath(Unknown Source)
at sun.java2d.loops.ProcessPath.fillPath(Unknown Source)
at sun.java2d.pipe.BufferedRenderPipe.fillPath(Unknown Source)
at sun.java2d.pipe.BufferedRenderPipe.fill(Unknown Source)
at sun.java2d.pipe.BufferedRenderPipe.fillOval(Unknown Source)
at sun.java2d.SunGraphics2D.fillOval(Unknown Source)
at Draw.drawCircle(Draw.java:40)
at Draw.drawCircle(Draw.java:41)
Here are lines 40 and 41:
g.fillOval(x, y, d, d);
drawCircle(x, y, d, it--);
Thanks for the help.
user2296424
source
share