title: Resizing Shape almost works
body: <p>I am trying to complete the resizing of a shape task I almost got the result I wanted, only dragging after the mouse changes to a resize cursor first draws another shape of the same type and resizes this Second drawn shape. Resulting in such a picture :</p>
  
  <p><img src="https://i.stack.imgur.com/ezXq9.png" alt="enter image description here"></p>
  
  <p>This is my related code:</p>
  
  <pre><code>  @Override
  public void mouseMoved(MouseEvent e) {
  
      if (e.isControlDown()) {
          updateShapeUnderMouse(e.getX(), e.getY());
      } // deals with drawing shape if control button held
  
      //deals with identifying shape to resize
          int x = e.getX();
           int y = e.getY();
  
      for (int i = myShapes.size() - 1; i &gt;= 0; i--) {
          Shape s = (Shape) myShapes.get(i);
              if (s.isedgePoint(x, y)) {
              ShapetoResize = s;
              setCursor(crnw);
              prevDragX = x;
              prevDragY = y;
              return;
          }
      }
  
  @Override
  public void mouseDragged(MouseEvent event) {
  
           if (event.isControlDown()) {
              if (shapeUnderMouse != null) {
              shapeUnderMouse.setXPos(event.getX());
              shapeUnderMouse.setYPos(event.getY());
              repaint();
          }
      } // deals with moving the shape
  
    //deals with identifying and resizing shape
      int x = event.getX();
      int y = event.getY();
  
       if (ShapetoResize != null) {
           if (ShapetoResize instanceof Square) {
              ShapetoResize.resizeSE(x - prevDragX, y - prevDragY);
          } else if (ShapetoResize instanceof Rectangle) { // SAME CODE FOR EACH SHAPE
     }
  
    repaint();
      }
  }
  </code></pre>
  
  <p>Any idea what might be happening? </p>
  
  <pre><code>public ArrayList&lt;Shape&gt; myShapes = new ArrayList();
  
  
  @Override
  public void paintComponent(Graphics g) {
  
      super.paintComponent(g);
      int length = myShapes.size();
  
      for (int i = 0; i &lt; length; i++) {
  
          myShapes.get(i).paint(g);
      }
  
  }
  </code></pre>