How To Delete objet whit mouse click ?

Posted by Meko on Stack Overflow See other posts from Stack Overflow or by Meko
Published on 2010-03-24T18:52:10Z Indexed on 2010/03/24 18:53 UTC
Read the original article Hit count: 143

Filed under:
|
|

Hi all. I made a simple FlowChat Editor that creates rectangles and triangles and connect them each other and shows the way from up to down. I can move this elements on screen to .But I am tying to create button to delete element which I clicked. There is problem that I can delete mytriangle object but but I cant delete myRectangle objects.It deletes but not object which i clicked.I delete from first object to last ..Here my code ...

 if (deleteObj) {

        if (rectsList.size() != 0) {
            for (int i = 0; i < rectsList.size(); i++) {
                MyRect rect = (MyRect) rectsList.get(i);
                if (e.getX() <= rect.c.x + 50 && e.getX() >= rect.c.x - 50
 && e.getY() <= rect.c.y + 15 && e.getY() >= rect.c.y - 15) {
                    rectsList.remove(rect);
                    System.out.println("This is REctangle DELETED\n");

                }

            }
        }
        if (triangleList.size() != 0) {
            for (int j = 0; j < triangleList.size(); j++) {
                MyTriangle trian = (MyTriangle) triangleList.get(j);

                if (e.getX() <= trian.c.x + 20 && e.getX() >= trian.c.x - 20 
&& e.getY() <= trian.c.y + 20 && e.getY() >= trian.c.y - 20) {
                    triangleList.remove(trian);
                    System.out.println("This is Triangle  Deleted\n");

                }

            }
        }

© Stack Overflow or respective owner

Related posts about java

Related posts about delete