未定义(乌龟)类型
Undefined for a type (of turtle)
嗨,我正在为我的 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 201812\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 201812\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 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 55]
Error: Turtle cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 56]
Error: tim cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 57]
Error: tim cannot be resolved to a variable
etc..
tim.drawPhase1()
和 tim.drawPhase2()
调用 Turtle class 中的方法或中间方法,这些方法似乎是在 class 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);
}
嗨,我正在为我的 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 201812\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 201812\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 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 55]
Error: Turtle cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 56]
Error: tim cannot be resolved to a variable
File: C:\Users\nhock\Desktop\School Work\UNCC Fall 201812\ITIS_1212\bookClasses\FaceCaptions.java [line: 57]
Error: tim cannot be resolved to a variable
etc..
tim.drawPhase1()
和 tim.drawPhase2()
调用 Turtle class 中的方法或中间方法,这些方法似乎是在 class 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);
}