我创建了矩形和插入的值,如X,Y,宽度和高度。当我调用fillRect或drawRect时,它表示方法fillRect不适用于参数(double,double,double,double)。
rectangle=new Rectangle(500,120,1000,20);
g.fillRect(rectangle.getX(),rectangle.getY(),rectangle.getWidth(),rectangle.getHeight());
当我使用整数变量而不是数字时,也会发生这种情况。任何建议?谢谢。
答案 0 :(得分:3)
fillRect
和drawRect
方法采用int
个参数,而非double
。您有两种选择:
Graphics2D
,请使用g.fill(rectangle)
代替fillRect
。将参数投射到int
g.fillRect((int) rectangle.getX(),(int) rectangle.getY(),
(int) rectangle.getWidth(),(int) rectangle.getHeight());