Is there a way to draw shapes in general as discrete entities like in photoshop every rectangle drawn is an object that can be deleted, moved, removed especially when the object removed I remove the object in the code and it's removed from the JPanel or canvas I draw on instead of drawing the same object with the canvas background which I think is inefficient way.
For example, when we draw a rectangle using Grahpics2D we use commands like.
@Override
public void paintComponent(Graphics canvas){
super.paintComponent(canvas);
((Graphics2D) canvas).drawRect(20,20,100,100);
}
Now this drawn rectangle is associated with the upper-left vertex position and width and height. It's not associated with Rectangle object so there is no way to refer to the rectangle after it's drawn.