2012-10-24 34 views
2

我遇到的问题是我想填充一个椭圆形,但我使用浮点数作为我的'x'和'y'值。以下是我有:如何在Java中重写fillOval函数?

@Override 
public void paintComponent(Graphics g) 
{ 
. 
. 
. 
for(Coordinates cord : tempVertices) 
{ 
    g.fillOval(cord.x,cord.y,DIAMETER,DIAMETER); 
} 
// DIAMETER = 10 

// Coordinate Class is just a variable with an 'x' and 'y' value stored in floats 
// Floats range from 0 to 1, so type casting won't work... 

// tempVertices is just an ArrayList with Coordinates values 

我使用NetBeans IDE 7.2,我不知道如何重写fillOval方法,我不能使用导入:import org.newdawn.slick.*;(它不会承认它)。有没有更好的Graphics选项或更简单的方法来实现这个简单的fillOval

+0

什么是'g'?看起来你想重写“别人的”代码? – John3136

+0

这是在一个重载的paintComponent(图形克)功能... –

+0

你可以只投你的浮标整数? 'g.fillOval((int)(coord.x),(int)(coord.y)...' – John3136

回答

4

您可能正在寻找的Graphics2Dfill()方法,它可以接受任何Shape

g.fill(new Ellipse2D.Float(cord.x, cord.y, DIAMETER, DIAMETER)); 

你还需要探索任何支持java.awt.RenderingHints

+0

完美的作品!谢谢! –