嗨,我正在为类(class)做作业,但最后一部分遇到了一些麻烦。这部分我正在编写代码来绘制一些阶段,并放入一个具有图片背景和一些自定义功能的世界中。我认为阶段的代码是问题所在。你们能帮我检查一下吗?
import java.awt.Color;
public class FaceCaptions
{
public static void main(String [] args)
{
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);
pic.show();
Turtle tim = new Turtle(424,906,pic);
tim.setPenColor(Color.red);
tim.setPenWidth(6);
tim.penDown();
tim.moveTo(440,1046);
tim.moveTo(522,1133);
tim.moveTo(597,1133);
tim.moveTo(671,1063);
tim.moveTo(688,1009);
tim.moveTo(698,882);
tim.moveTo(657,790);
tim.moveTo(495,771);
tim.moveTo(424,906);
// draw the features
tim.moveTo(450, 910);
tim.drawEyeglasses(450, 910, 5, Color.white);
tim.moveTo(505, 1020);
tim.drawMustache(505,1020, 2, Color.black);
//Create Phase 1
tim.moveTo(400,1300);
tim.turnLeft();
tim.drawPhase1();
//Create Phase 2
tim.moveTo(300,1450);
tim.drawPhase2();
}
public static void drawPhase1()
{
TurtleAlphabet.drawABoldSize(tim, Color.blue, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.white, true, 1);
TurtleAlphabet.drawKBoldSize(tim, Color.red, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.blue, true, 1);
TurtleAlphabet.drawABoldSize(tim, Color.white, true, 1);
TurtleAlphabet.drawRBoldSize(tim, Color.red, true, 1);
TurtleAlphabet.drawDBoldSize(tim, Color.blue, true, 1);
}
public static void drawPhase2()
{
TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.orange, true, 1);
TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
TurtleAlphabet.drawRBoldSize(tim, Color.orange, true, 1);
TurtleAlphabet.drawDBoldSize(tim, Color.yellow, true, 1);
}
}
这是系统的响应:
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java [line: 45]
Error: The method drawPhase1() is undefined for the type Turtle
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java [line: 50]
Error: The method drawPhase2() is undefined for the type Turtle
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java [line: 55]
Error: Turtle cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java [line: 56]
Error: tim cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 2018\1212\ITIS_1212\bookClasses\FaceCaptions.java [line: 57]
Error: tim cannot be resolved to a variable
etc..
tim.drawPhase1()
和tim.drawPhase2()
调用Turtle类中的方法或中间的方法,看起来这些方法是在Turtle类上定义的,修改代码以静态使用drawPhase1,2方法并传递Turtle实例
FaceCaptions.drawPhase1(tim);
FaceCaptions.drawPhase2(tim);
public static void drawPhase1(Turtle tim){
TurtleAlphabet.drawABoldSize(tim, Color.blue, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.white, true, 1);
TurtleAlphabet.drawKBoldSize(tim, Color.red, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.blue, true, 1);
TurtleAlphabet.drawABoldSize(tim, Color.white, true, 1);
TurtleAlphabet.drawRBoldSize(tim, Color.red, true, 1);
TurtleAlphabet.drawDBoldSize(tim, Color.blue, true, 1);
}
public static void drawPhase2(Turtle tim){
TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
TurtleAlphabet.drawWBoldSize(tim, Color.orange, true, 1);
TurtleAlphabet.drawABoldSize(tim, Color.yellow, true, 1);
TurtleAlphabet.drawRBoldSize(tim, Color.orange, true, 1);
TurtleAlphabet.drawDBoldSize(tim, Color.yellow, true, 1);
}
我是一名优秀的程序员,十分优秀!