How can I make a shape tool similar to illustrator?

Hi I'm trying to get the rectangle to be resizable using the mouse. Similar to the rectangle tool in illustrator or MS paint. I've tried adding a function so that the x and y of the rectangle will follow the mouse but I can't seem to figure it out. Also sorry If I posted this wrong I'm very new to this site and this is all a little confusing.

`// Global variables
//ShapeRectangle rectangle;

//ArrayList<ShapeRectangle> rectangle;
//ArrayList<ShapeCircle> circle;

import java.util.List;
final List<ShapeRectangle> rectangle = new ArrayList<ShapeRectangle>();
final List<ShapeCircle> circle = new ArrayList<ShapeCircle>();
PImage exInterface;

boolean rectTool = false;
boolean circTool = false;
boolean lineTool = false;

float rectWidth;
float rectHeight;
float circWidth;
float circHeight;

// Initial application setup
void setup() {
  background(204);
  size(1000, 800);
  exInterface = loadImage("interface.png");
}

// The draw function is basically a while loop and constantly gets run
void draw() {
  // Set color of screen
  background(235);
  image(exInterface, 0, 0);//load interface
  // Render the rectangle
  for (ShapeRectangle r : rectangle) {
    r.display();
    r.mouseint();
  }
  //Render the circle
  for (ShapeCircle c : circle) {
    c.display();
    c.mouseint();
  }
}

void mousePressed() {
  // Add new rectangle when tool selected and mouse is pressed
  if (rectTool == true && mouseButton == LEFT) {
    rectangle.add( new ShapeRectangle (mouseX, mouseY, rectWidth + mouseX, rectHeight + mouseY) );
  }

  // Add new circle when tool selected and mouse is pressed
  if (circTool == true && mouseButton == LEFT) {
    circle.add( new ShapeCircle (mouseX, mouseY, circWidth + mouseX, circHeight + mouseY) );
  }

  redraw();
}

//Keyboard controls for the drawing tools
void keyPressed() {
  //Select rectangle tool
  if (key == '1') {
    rectTool = true;
    circTool = false;
    lineTool = false;
  }
  //Select circle tool
  if (key == '2') {
    rectTool = false;
    circTool = true;
    lineTool = false;
  }
  //Select line tool
  if (key == '3') {
    rectTool = false;
    circTool = false;
    lineTool = true;
  }
} `