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();
}}
在while循环中从不使用/增加'x1'和'y1'值 – 2013-03-05 02:55:06
在发布到任何位置之前设置代码的格式。 Eclipse - >'Ctrl' +'Shift' +'F',NetBeans - >'Alt' +'Shift' +'F' – Pshemo 2013-03-05 02:55:11