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

Rectangle.add(Point) does not add the point to the rectangle

XMLWordPrintable

    • 1.0beta2
    • x86
    • windows_nt
    • Verified

      Rectangle.add(Point) does not add the point to the rectangle
      Same problem with Rectangle.add(int, int).

      Steps to reproduce
      Compile the following code
      Run RectAdd.class

      /* Rectangle.Add() tests
       * @(#)RectAdd.java 1.1 07 Nov 1995 17:17:54
       * @author Kevin A. Smith
       *
       */

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

      public class RectAdd extends Applet
      {
          Rectangle r1 = new Rectangle(20, 10, 60, 60);
          Rectangle r2 = new Rectangle(70, 50, 60, 60);
          Point pt = new Point(150, 150);
          int outerX = 200;
          int outerY = 200;

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


          public void paint(Graphics g)
          {
             // local variables
             Rectangle rWithPt = (Rectangle) r1.clone();
             Rectangle rWithRect = (Rectangle) r1.clone();
             Rectangle rWithInt = (Rectangle) r1.clone();

             // draw rectangle 1
             g.setColor(Color.red);
             g.fillRect(r1.x, r1.y, r1.width, r1.height);

             // draw rectangle 2
             g.setColor(Color.blue);
             g.fillRect(r2.x, r2.y, r2.width, r2.height);

             // Rectangle.add(Rectangle) test
             // should draw a yellow line around the far edges of both
             // rectangles
             g.setColor(Color.yellow);
             rWithRect.add(r2);
             g.drawRect(rWithRect.x,
                        rWithRect.y,
                        rWithRect.width,
                        rWithRect.height);

             // draw point
             g.setColor(Color.black);
             g.fillOval(pt.x - 2, pt.y - 2, 3, 3);

             // Rectangle.add(Point) test
             // should draw a magenta line around the rectangle and the
             // point
             rWithPt.add(pt);
             g.setColor(Color.magenta);
             g.drawRect(rWithPt.x, rWithPt.y, rWithPt.width, rWithPt.height);

             // draw integers
             g.setColor(Color.black);
             g.fillOval(outerX - 2, outerY - 2, 3, 3);

             // Rectangle.add(int, int) test
             // should draw a green line around the rectangle and the
             // drawn point
             rWithInt.add(outerX, outerY);
             g.setColor(Color.green);
             g.drawRect(rWithInt.x, rWithInt.y, rWithInt.width, rWithInt.height);

          } // end paint()

          public static void main(String args[])
          {
             Applet a = new RectAdd();
             a.init();
             a.start();

             AppFrame f = new AppFrame("Rectangle.add() Tests");
             f.add(a);
             f.resize(400, 400);
             f.show();
          }

      }

      /* Generic Application Frame
       * @(#)AppFrame.java 1.1 07 Nov 1995 17:17:55
       * @author Kevin A. Smith
       */

      import java.awt.Frame;
      import java.awt.Event;

      class AppFrame extends Frame
      {
          public AppFrame(String name)
          {
             super(name);
          }

          public boolean handleEvent(Event e)
          {
             if (e.id == Event.WINDOW_DESTROY)
             {
                System.exit(0);
                return true;
             }
             else
                return super.handleEvent(e);
          }
      }

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: