Hi everyone,

How to select already drawn single or multiple shapes . I want to select shapes when i draw rectangle around it and when i click on blank area it deletects it. I need selection for copy, pase, move and delete operation.

I don't know where to start to achieve this functionality.

I had used following function but it only checks if point is in the ellispe.

    public boolean isInsideEllipse(Point point) {
        return new Ellipse2D.Float(xbegin, ybegin, width, height).contains(point);
    }

Pleaes guide me, how to perform these operations. Thanks !

First, selecting a shape by clicking inside it...
the contains method comes from Shape, so assuming you have some kind of list of the existing shapes you can iterate through that to see which Shape contains the mouse pressed point (if you allow overlapping shapes then there may be more than 1 such shapes)

for a dragged rectangle selection...
create the selection Rectangle defined by the mouse drag start and latest points. The Rectangle class has acontains(Rectange other) method, so you can iterate through your Shapes, for each Shape get its bounding rectangle (getBounds()), then see if the selection rectangle contains that bounding rectangle.

Yes I am maintaining a list of shapes, but I am storing objects of shapes not java.awt.Rectangle shape object. Therefore I don't have getBounds() method in it.

How should I check if shape is in selection rectangle bounds ?

Rectangle is a Shape. All Shapes implement getBounds()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.