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

Win32 only: Graphics.fillOval() is off by a couple of pixels

    Details

    • Subcomponent:
    • Resolved In Build:
      1.0fcs
    • CPU:
      x86
    • OS:
      windows_nt
    • Verification:
      Verified

      Description

      For bookkeeping purposes only.
      Win32 only: Graphics.fillOval() draws filled ovals one pixel too small in both
      width and height.

      Steps to reproduce:
      Compile and run the attached code.
      //note: you will also need /usr/green2/sqe/kas-tests/AppletFrame.java
      // to compile this.

      /* test Ovals */

      import java.applet.Applet;
      import java.awt.*;


      public class FillOvalTest extends Applet
      {
         // class variables
         private OvalTestCanvas ovalTestCanvas;

         public FillOvalTest()
         {
            setLayout( new BorderLayout() );
            add("North", new OvalTestCP(this) );
            add("Center", ovalTestCanvas = new OvalTestCanvas() );
         }

         public void testOval( String xVal,
                               String yVal,
                               String widthVal,
                               String heightVal )
         {
            // local variables
            Rectangle bounds;
            int x, y, width, height;
            
            x = Integer.parseInt(xVal);
            y = Integer.parseInt(yVal);
            width = Integer.parseInt(widthVal);
            height = Integer.parseInt(heightVal);

            bounds = new Rectangle(x, y, width, height);
            ovalTestCanvas.setBounds(bounds);

         }


         public void init()
         {
            resize(400, 400);
         }


         public static void main(String argv[])
         {
            AppletFrame.startApplet("FillOvalTest", "Fill Oval Test", argv);
         }
      }


      class OvalTestCanvas extends Canvas
      {
         // class variables
         private Rectangle ovalBounds;

         public void setBounds(Rectangle bounds)
         {
            if( ( ovalBounds == null ) || (! ovalBounds.equals(bounds) ) )
            {
               ovalBounds = bounds;
               repaint();
            }
         }

         public void paint(Graphics g)
         {
            
            if( ovalBounds != null )
            {
               // fill yellow oval
               g.setColor(Color.yellow);
               g.fillOval( ovalBounds.x,
                           ovalBounds.y,
                           ovalBounds.width,
                           ovalBounds.height );

               // draw black oval
               g.setColor(Color.black);
               g.drawOval( ovalBounds.x,
                           ovalBounds.y,
                           ovalBounds.width,
                           ovalBounds.height );

            } // if the bounds have been set.
            else
            {
               g.drawString( "Bounds not set", 10, 10 );
            }
         }
      }


      class OvalTestCP extends Panel
      {
         // class variables
         private FillOvalTest applet;
         private final String TEST_OVAL = "Test Oval";
         private TextField xField;
         private TextField yField;
         private TextField widthField;
         private TextField heightField;

         public OvalTestCP(FillOvalTest fot)
         {
            applet = fot;

            add( xField = new TextField( "10", 3 ) );
            add( yField = new TextField( "10", 3 ) );
            add( widthField = new TextField( "10", 3 ) );
            add( heightField = new TextField( "10", 3 ) );
            add( new Button(TEST_OVAL) );
         }
         
         public boolean action(Event evt, Object obj)
         {
            if( evt.target instanceof Button )
            {
               String label = (String) obj;
               if( label.equals(TEST_OVAL) )
                  applet.testOval( xField.getText().trim(),
                                   yField.getText().trim(),
                                   widthField.getText().trim(),
                                   heightField.getText().trim() );
               else
                  return false;

               return true;
            }
            else
               return super.action(evt, obj);
         }
      }

        Attachments

          Activity

            People

            • Assignee:
              flar Jim Graham
              Reporter:
              kasmithsunw Kevin Smith (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: