Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4269933

java.awt.Polygon.getBounds() does not update the bounds

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.8, 1.2.0
    • client-libs
    • 2d
    • 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)
      ======================================================================

            flar Jim Graham
            wleesunw William Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: