我正在尝试运行一个用颜色填充圆圈的程序,我不确定我做错了什么,我的 fillOval 命令出现找不到符号错误,这是我的代码。此外,填充颜色应与绘制的圆圈相同。
import javax.swing.JApplet;
import java.awt.*;
import java.util.Random;
public class Drawing extends JApplet
{
public void paint(Graphics page)
{
Random generator=new Random();
float r = generator.nextFloat();
float g = generator.nextFloat();
float b = generator.nextFloat();
Color randomColor = new Color(r, g, b);
int random,randomx,randomy;
int x,y;
int width, height;
setBackground(Color.white);
random=generator.nextInt(24)+8;
randomx=generator.nextInt(24);
randomy=generator.nextInt(24);
x=randomx;
y=randomy;
width=random*2;
height=random*2;
page.drawOval(x, y, width, height);
page.setColor(randomColor);
fillOval(x, y,width,height);
}
}
最佳答案
fillOval
是 Graphics
的方法,而不是自定义 Drawing
类的方法。
fillOval(x, y, width, height);
应该是
page.fillOval(x, y, width, height);
关于java - 用颜色填充圆圈,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23227524/