因此,我正在开发一个基本的绘画程序,该程序需要具有绘制圆圈的工具。我创建了一个名为Circle的类,该类将在其中发生。我正在尝试将Circle.class内部的方法drawCircle调用到我的Main文件中。这是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的一半。

10-06 08:56