0
我编译了以前的代码后,它的工作,但现在我不能得到的圆周围改变为圆内的什么不同的颜色。有什么建议么。100随机圈
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Dimension d = getSize();
for(int i = 0; i < 100; ++i)
{
Color color = new Color(generator.nextInt(255), generator.nextInt(255), generator.nextInt(255));
g.setColor(color);
int circleSize = generator.nextInt(d.width/4);
int x = generator.nextInt(d.width - circleSize);
int y = generator.nextInt(d.height - circleSize);
g.fillOval(x, y, circleSize, circleSize);
color = new Color(generator.nextInt(255), generator.nextInt(255), generator.nextInt(255));
g.setColor(color);
g.drawArc(x, y, circleSize, circleSize, 0, 360);
}
}
}
我会避免包装,如果我有一定的大小,里面没有东西。 – Tomas
它似乎运行,因为它应该在这里。适当的尺寸,大量的圈子和黑色的背景。唯一没有编译的是你的第二个导入,'javax.swing.JPanel *;'。我删除了该行,并且一切正常。你修改了你在这里写的代码吗? – afsantos
我已经删除了该导入行并尝试了它,没有发生任何事情。所以我也尝试改变背包,但仍然没有任何东西..我现在无语了。 –