我在大学的第一个学期,正在使用教育simpleturtle / turtle类进行小型作业。
我正在使用Dr.Java(IDE)编写我的程序,当我运行我的程序时,它编译完全正常,但是当我运行程序时,每次运行它时它都会在随机点跳出执行。当它跳出来时它永远不会保持一致,但只有当我运行这个我一直在研究的程序时才会这样做。
当我回去运行它们时,我所有其他程序都运行良好。就是这个。 我已经卸载并重新安装了jdk和dr。 java,我重新启动了我的电脑,重置为博士的默认值。 java,并重新映射我的额外类路径链接到我的教育课程文件,没有骰子。 有什么想法吗?
import java.util.*;
import java.awt.*;
/**
* Class that represents a turtle which is similar to a Logo turtle.
* This class inherts from SimpleTurtle and is for students
* to add methods to.
*
* Copyright Georgia Institute of Technology 2004
* @author Barb Ericson ericson@cc.gatech.edu
*/
public class Turtle extends SimpleTurtle
{
////////////////// constructors ///////////////////////
/** Constructor that takes the x and y and a picture to
* draw on
* @param x the starting x position
* @param y the starting y position
* @param picture the picture to draw on
*/
public Turtle (int x, int y, Picture picture)
{
// let the parent constructor handle it
super(x,y,picture);
}
/** Constructor that takes the x and y and a model
* display to draw it on
* @param x the starting x position
* @param y the starting y position
* @param modelDisplayer the thing that displays the model
*/
public Turtle (int x, int y,
ModelDisplay modelDisplayer)
{
// let the parent constructor handle it
super(x,y,modelDisplayer);
}
/** Constructor that takes the model display
* @param modelDisplay the thing that displays the model
*/
public Turtle (ModelDisplay modelDisplay)
{
// let the parent constructor handle it
super(modelDisplay);
}
/**
* Constructor that takes a picture to draw on
* @param p the picture to draw on
*/
public Turtle (Picture p)
{
// let the parent constructor handle it
super(p);
}
/////////////////// methods ///////////////////////
public static void main(String[] args)
{
World earth = new World();
Turtle t1 = new Turtle(earth);
t1.forward();
}
public void drawT() {
this.forward(100);
this.turnLeft();
this.penUp();
this.forward(40);
this.turn(180);
this.penDown();
this.forward(80);
this.hide();
}
public void drawSquare()
{
this.turnRight();
this.forward(30);
this.turnRight();
this.forward(30);
this.turnRight();
this.forward(30);
this.turnRight();
this.forward(30);
}
public void drawSquare2()
{
int width = 30;
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
}
/**
* Method to draq a square with a width and height
* of some passed amount.
* @param width the width and height to use
*/
public void drawSquare(int width)
{
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
this.turnRight();
this.forward(width);
}
public void drawHorns(int x, int y, Color c){
//written for large foreground element
//set pen up til you move turtle to location to draw mustache
this.penUp();
//move to coordinates to draw eyeglasses
this.moveTo(x, y);
//set pen color
this.setPenColor(c);
//set pen width
this.setPenWidth(4);
//move left
this.turnLeft();
this.forward(20);
//set pen down
this.penDown();
//turn up
this.turnRight();
//draw left horn - angled out
this.turn(-65);
this.forward(20);
this.turn(30);
this.forward(20);
this.turn(30);
this.forward(20);
this.turn(30);
this.forward(20);
this.turn(30);
this.forward(5);
this.turn(125);
this.forward(20);
this.turn(-30);
this.forward(10);
this.turn(-30);
this.forward(34);
this.turn(90);
this.forward(25);
//move away to draw the other set of horns
this.turn(-110);
//put a pen up here
this.penUp();
this.forward(130);
//put a pen down here
this.penDown();
//draw right side of the horns
this.turn(-125);
this.forward(25);
this.turnRight();
this.forward(20);
this.turn(-30);
this.forward(20);
this.turn(-30);
this.forward(20);
this.turn(-30);
this.turnRight();
this.turn(90);
this.forward(20);
this.turn(30);
this.forward(20);
this.turn(30);
this.forward(20);
this.turn(20);
this.forward(20);
//pen up
this.penUp();
}
public void drawCensor(int x, int y, Color c){
//pen up
this.penUp();
//move to location
this.moveTo(x,y);
//set pen color
this.setPenColor(c);
//set pen width
this.setPenWidth(20);
//pendown
this.penDown();
//draw censor bar
this.turnRight();
this.forward(5);
this.turn(180);
this.forward(10);
//penUp
this.penUp();
}
public void drawEyeglasses(int x, int y, Color c){
//pen up
this.penUp();
//move to location
this.moveTo(x,y);
//set pen color
this.setPenColor(c);
this.setPenWidth(2);
//pen down
this.penDown();
//draw middle stem
this.turnLeft();
this.forward(3);
this.turn(180);
this.forward(6);
//draw right eyeglass piece
this.turnLeft();
this.forward(3);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(6);
this.turn(45);
this.forward(3);
//move to left side
this.turnLeft();
this.forward(6);
this.turnRight();
this.forward(3);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(6);
this.turn(-45);
this.forward(3);
//penup
this.penUp();
this.setHeading(90);
}
}
// this } is the end of class Turtle, put all new methods before this
// Face Features Program
import java.awt.Color;
public class FaceFeatures
{
public static void main(String [] args)
{
//Choose Background Image for Program
String filename;
if (args.length > 0) {
// got a filename passed into program as a runtime parameter
filename = args[0];
System.out.println("Filename passed in: " + filename);
} else {
// ask user for a picture
filename = FileChooser.pickAFile();
System.out.println("User picked file: " + filename);
}
// use the filename to create the picture object
Picture pic = new Picture(filename);
// create turtle
Turtle daniel = new Turtle(pic);
//show pic for writing program
pic.show();
//set pen up
daniel.penUp();
//set pen color and thickness
daniel.setPenColor(Color.red);
daniel.setPenWidth(5);
//move to starting coordinate
daniel.moveTo(173,162);
//set pen down
daniel.penDown();
//outline face
daniel.moveTo(173, 162);
daniel.moveTo(165, 170);
daniel.moveTo(165, 184);
daniel.moveTo(146, 192);
daniel.moveTo(141, 205);
daniel.moveTo(132, 213);
daniel.moveTo(126, 235);
daniel.moveTo(117, 259);
daniel.moveTo(114, 286);
daniel.moveTo(114, 311);
daniel.moveTo(121, 339);
daniel.moveTo(128, 359);
daniel.moveTo(141, 375);
daniel.moveTo(161, 385);
daniel.moveTo(176, 383);
daniel.moveTo(189, 376);
daniel.moveTo(210, 349);
daniel.moveTo(242, 321);
daniel.moveTo(255, 304);
daniel.moveTo(266, 287);
daniel.moveTo(272, 276);
daniel.moveTo(282, 263);
daniel.moveTo(289, 252);
daniel.moveTo(293, 226);
daniel.moveTo(289, 213);
daniel.moveTo(266, 217);
daniel.moveTo(258, 212);
daniel.moveTo(259, 205);
daniel.moveTo(238, 208);
daniel.moveTo(219, 200);
daniel.moveTo(193, 185);
daniel.moveTo(190, 183);
daniel.moveTo(177, 167);
daniel.moveTo(173, 162);
//Draw Horns Method
daniel.drawHorns(195, 110, Color.red);
//setheading
daniel.setHeading(0);
//sensor over the male homonid
daniel.drawCensor(398, 395, Color.black);
//setheading
daniel.setHeading(0);
//sensor over the female homonid
//setheading
daniel.setHeading(0);
daniel.drawCensor(472, 309, Color.black);
//setheading
daniel.setHeading(0);
daniel.drawCensor(537, 317, Color.black);
//set heading
daniel.setHeading(0);
//draw eyeGlasses method ( on male homonid )
daniel.drawEyeglasses(388, 182, Color.green);
//set heading
daniel.setHeading(0);
//draw eyeGlassesmethod ( on female homonid )
daniel.drawEyeglasses(531, 228, Color.magenta);
}
}
答案 0 :(得分:-1)
尝试编辑构造函数。或者,可能是末端大括号放错了位置