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 !

3 Weeks
Discussion Span
Last Post by JamesCherrill

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.

Edited by JamesCherrill


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 ?

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.