gpt4 book ai didi

java turtle 图形和迭代

转载 作者:行者123 更新时间:2023-12-01 10:48:30 31 4
gpt4 key购买 nike

import java.awt.*;
public class TurtleGraphicsDemo2 {
public static void main(String[] args) {
World worldObj = new World();
Turtle myrtleTheTurtle = new Turtle(0, 0, worldObj);
drawLine(myrtleTheTurtle, Color.RED, 10, 20, 50, 20); //invokes the first drawLine() method
drawLine(myrtleTheTurtle, 100, 150, 50, -45); //invokes the second drawLine() method
drawLine(myrtleTheTurtle, 100, 150, 100, 60); //invokes the second drawLine() method
drawLine(myrtleTheTurtle, Color.BLUE, 10, 40, 100, 40); //invokes the first drawLine() method
}//end of main method
}//end of class

错误如下:

TurtleGraphicsDemo2.java:19:错误:找不到符号

   drawLine(myrtleTheTurtle, Color.RED, 10, 20, 50, 20);      
^

符号:方法drawLine(Turtle,Color,int,int,int,int) 位置:类TurtleGraphicsDemo2

我的编程老师给了我们这个来实验,但我收到了一个drawLine错误,有人知道为什么吗?我对Java没有太多经验,只有Python。如果您能解决这个问题,或者知道我如何解决它,谢谢。如果没有,谢谢您的浏览:)

最佳答案

您只能使用Graphics2DCanvas内绘制线条

   class MyCanvas extends Canvas {

public MyCanvas () {
setBackground (Color.GRAY);
setSize(300, 300);
}

public void paint (Graphics g) {
Graphics2D g2;
g2 = (Graphics2D) g;
g2.drawString ("It is a custom canvas area", 70, 70);
}
}

关于java turtle 图形和迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34047985/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com