[英]Dr. Java compiles my program with no errors/issues but isn't running the code to completion
I'm in my first semester at university and am working on a small assignment using the educational simpleturtle/turtle class(es).我在大学的第一个学期,正在使用教育 simpleturtle/turtle class(es) 完成一项小作业。
I'm writing my programs using Dr. Java (IDE), and when I go to run my program, it compiles completely fine, but when I run the program it jumps out of execution at random points each time I run it.我正在使用 Dr. Java (IDE) 编写我的程序,当我去运行我的程序时,它编译得非常好,但是当我运行该程序时,它每次运行时都会在随机点跳出执行。 It's never consistent on when it jumps out, but only does it when I run this program that I've been working on.
它跳出的时间从来都不是一致的,但只有在我运行这个我一直在研究的程序时才会出现。
All my other programs work fine, when I go back to run them.当我回去运行它们时,我所有的其他程序都可以正常工作。 It's just this one.
就这一个。 I've uninstalled and reinstalled jdk and dr.
我已经卸载并重新安装了 jdk 和 dr。 java, I've restarted my computer, reset to the defaults on dr.
java,我已经重新启动了我的计算机,在博士上重置为默认值。 java, and re-mapped my extra classes path link to my educational course files and no dice.
java,并将我的额外课程路径链接重新映射到我的教育课程文件,没有骰子。 Any ideas?
有任何想法吗?
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);
}
}
Try Editing your constructor.尝试编辑您的构造函数。 Or, perhaps theres a misplaced end curly bracket
或者,也许有一个放错位置的大括号
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.