gpt4 book ai didi

java - 找不到符号类 drawCircle

转载 作者:行者123 更新时间:2023-12-02 11:09:25 25 4
gpt4 key购买 nike

因此,我正在开发一个基本的绘图程序,该程序需要一个绘制圆圈的工具。我创建了一个名为 Circle 的类,在其中执行该操作。我正在尝试将 Circle.class 中的方法 drawCircle 调用到我的主文件中。这是 Circle.class

导入 java.awt.*;
公共(public)类圈子{

private int x, y, radius;

public Circle(int x, int y, int radius) {
this.x=x;
this.y=y;
this.radius=radius;
}
//left/right coordinate for center
public int getx(){
return x;
}
//up/down coordinate for center
public int gety(){
return y;
}
//circle's radius(half the diameter)
public int getRadius(){
return radius;
}
//draws the circle

public void drawCircle(Graphics g){
Expo.drawCircle(g,x,y,radius);
}

public void setx(int x){
this.x=x;
}

public void sety(int y){
this.y=y;
}

public void setRadius(int Radius){
this.radius=radius;
}

}

现在我需要把它移到这里的案例结构中(案例5)
public void toolClick(Graphics g)
{
int radius = getRadius(centerX,centerY,rimX,rimY);

switch(numTools)
{
//Pencil Tool
case 1:
//Determines the selected size of the pencil tool.
switch(numSize)
{
case 1: Expo.fillCircle(g,xCoord,yCoord,5); break;
case 2: Expo.fillCircle(g,xCoord,yCoord,15); break;
case 3: Expo.fillCircle(g,xCoord,yCoord,30); break;
}
break;
//Rectangle Tool
case 2:
Expo.drawRectangle(g,x1,y1,x2,y2);
break;
//Eraser Tool
case 3:
Expo.setColor(g,Colors.white);
Expo.fillCircle(g,xCoord,yCoord,30);
break;
//Line Tool
case 4:
Expo.drawLine(g,startX,startY,endX,endY);
break;
//Circle Tool(Very Broken)
case 5:
Circle tool = new Circle.drawCircle(g); //<-- ERROR!!!!!!!!
tool.drawCircle(g);
break;
//Reset Tool
case 6:
Expo.setColor(g,Colors.white);
Expo.fillRectangle(g,0,81,1000,650);
break;
//Fill Tool
case 7:
Expo.fillRectangle(g,0,81,1000,650);
break;
//Crazy Rectangle tool(not broken)
case 8:
Expo.drawRectangle(g,startX,startY,endX,endY);
break;
//Crazy Circle tool(not broken)
case 9:
Expo.drawCircle(g,centerX,centerY,radius);
break;
//Crazy Line tool(not broken)
case 10:
Expo.drawLine(g,startX,startY,endX,endY);
break;
}
}

这是我得到的错误
F:\PreAP Computer Science\Paint Program\HashTagTeamPaint.java:278: cannot find symbol
symbol : class drawCircle
location: class Circle
Circle tool = new Circle.drawCircle(g);
^

非常感谢所有帮助!谢谢!

最佳答案

您的代码可能应该只是

   Circle tool = new Circle(startX, startY, 10);
tool.drawCircle(g);

也就是说,首先创建一个 Circle 对象,然后在其上调用 drawCircle。
您还需要弄清楚如何将半径传递给圆
硬编码半径为 10。

关于java - 找不到符号类 drawCircle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23502991/

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