0
即时尝试实现getBounds()方法,但我不能让工会工作;我不知道工会如何运作。我的代码如下:为什么isnt Rectangle2D.createUnion()为我工作?
public Rectangle2D getBounds2D() {
Rectangle2D rec= new Rectangle2D.Double();
Rectangle2D temp;
for(int i=0; i<shapes.size(); i++){
temp = new Rectangle2D.Double(shapes.get(i).getBounds2D().getX(),shapes.get(i).getBounds2D().getY(),shapes.get(i).getBounds2D().getWidth(), shapes.get(i).getBounds2D().getHeight());
rec.createUnion(temp);
}
return rec;
}
shapes变量是Shapes的数组列表。
我使用温度在该ArrayList
伊夫创建使用从每个形状的边界的矩形的getBounds用过()。的getWidth /高度上温度,看它是否正在返回奇怪的数字,但在数字看起来细。当我打电话给rec.getBounds.getWidth /高度时,我都得到0.0。从这里,我假设我没有正确使用union()。有没有人有任何见解,我可以做什么?谢谢!