我一直在想:为什么该paint()方法不会生成StackOverflowError?我知道paint()必须在后台重复运行,但是什么限制它只能以计算机可以处理的速度调用它而不会产生StackOverflowError?那么它不会重复paint()到使用太多内存的程度?
我正在制作一个随机的线发生器以获得乐趣.出于某种原因,程序没有使用我在nextInt().Strangely中提供的最大数字,唯一nextInt()正常工作的是space.
这里是我的代码:
public class LineFractal extends Applet {
Random rnd = new Random();
int width = 640;
int height = 640;
int x = 1000;
int endy1 = rnd.nextInt(320);
int endx1 = rnd.nextInt(320);
int starty1 = rnd.nextInt(320);
int startx1 = rnd.nextInt(320);
int space = rnd.nextInt(25);
public void init() {
setSize(width, height);
Frame c = (Frame)this.getParent().getParent();
c.setTitle("Line Generator");
}
public void paint(Graphics g) {
while (x > 0) {
x -= 1;
g.drawLine(startx1, starty1, endx1, endy1); …Run Code Online (Sandbox Code Playgroud)