我正在使用java.awt.Rectangle
类和交集方法。如何从矩形交点获取单个数字
Rectangle rect1 = new Rectangle(1, 2, 3, 4);
Rectangle rect2 = new Rectangle(2, 3, 4, 5);
Rectangle intersection = rect1.intersection(rect2);
System.out.println(intersection);
输出是:
java.awt.Rectangle[x=2,y=3,width=2,height=3]
如何获得每个人多少?例如将答案分配给变量x = hello
或width = hi
。我想格式化输出为:
Intersection: (2.0, 3.0, 2.0, 3.0)
你检查了[documentation](https://docs.oracle.com/javase/8/docs/api/java/awt/Rectangle.html)吗? – shmosel
我通过玩弄得到答案.. 它'intersection.width' 但是,你如何转换,所以'矩形'接受浮动。文档说'Rectangle(int,int,int,int)'。 – futilecheese28
是的,你甚至尝试阅读文档?有一个getX,getY,getWidth和getHeight方法。 – ivange94