-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1.8, 1.2.0
-
generic, x86
-
generic, windows_98
Name: wl91122 Date: 09/08/99
java.awt.Polygon.getBounds() does not update the bounds (a protected Rectangle) when the Polygon is changed. Once 'bounds' is allocated,
successive calls to getBounds() will return the same bounds value (see source code: java.awt.Polygon.java). The trouble for me is that
getBounds() is called internally by the java.awt.Polygon.contains(...) routine. After I change the size or shape of a polygon, calls to contains(...)
will then not work correctly. Run these codes:
import java.awt.Polygon;
class test
{ public static void main(String[] args)
{ Polygon p = new Polygon(new int[] {10,10,20,20},new int[] {10,20,20,10},4); // actually a rectanle
System.out.print("Should be true, output is: ");
System.out.println( p.contains(15,15) ); // e.g. test a mouse click
for (int i=0;i<p.npoints;i++) { p.xpoints[i] *= 2;p.ypoints[i] *= 2;} // if you repaint the polygon and change its size
System.out.print("Should be true, output is: ");
System.out.println(p.contains(30,30));
}
}
The second time println will produce 'false', which is obvious wrong.
(Review ID: 94671)
======================================================================
- duplicates
-
JDK-4212883 Polygon object should expose methods for updating bounds after modifications
-
- Resolved
-