Dr.Java 不会运行我的程序,因为我的变量会永远存在,我不知道如何防止这种情况发生。如果你能告诉我如何解决这个问题,那就太好了。我是初学者,所以这对我来说都是陌生的。
这是该课程的代码:
import java.awt.Color;
class PaintablePicture extends Picture {
public PaintablePicture(String fileName) {
super(fileName);
}
public void purpleSplotch(int x, int y) {
int x1 = 0;
int y1 = 1;
while (x1 < x * 2)
while (y1 < y * 3)
{
Color purple = new Color(175, 0, 175);
Pixel pixRef;
pixRef = this.getPixel(x, y);
pixRef.setColor(purple);
}
return;
}
}
然后这就是我运行它的方法(忽略其他类的所有艺术乌龟的东西,一切都很好,直到我开始绘制可绘制的图片。
public class GraffitiApp
{
public static void main(String[] a)
{
FileChooser.pickMediaPath();
PaintablePicture pRef;
pRef = new PaintablePicture(FileChooser.pickAFile());
pRef.purpleSplotch(14,14);
pRef.purpleSplotch(17,20);
ArtisticTurtle tRef = new ArtisticTurtle(pRef);
tRef.pentagon(20);
tRef.spiral(50);
tRef.penUp();
tRef.forward(-50);
tRef.turn(90);
tRef.penDown();
tRef.letterK(50);
tRef.penUp();
tRef.turn(-130);
tRef.forward(100);
tRef.turn(90);
tRef.forward(140);
tRef.penDown();
tRef.letterK(30);
tRef.penUp();
tRef.moveTo(486, 60);
tRef.penDown();
tRef.star(30);
tRef.penUp();
tRef.moveTo(159,122);
tRef.turn(30);
tRef.penDown();
tRef.star(60);
tRef.penUp();
tRef.moveTo(330,103);
tRef.turn(-67);
tRef.penDown();
tRef.pentagon(40);
tRef.penUp();
tRef.moveTo(471,158);
tRef.penDown();
tRef.spiral(35);
pRef.explore();
} }