我想画这个:
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--); // centre
drawCircle(x - d, y, d, it--); // left
drawCircle(x + d, y, d, it--); // right
}
出于这个问题的目的,忽略我画圆圈的实际位置 – 我会稍后改变它,因为它不太正确.但是,我在程序的逻辑中哪里出错了?对我来说,似乎很清楚我称这种方法在每次迭代中绘制三个圆圈.这是我的错误:
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(U