How to delete object with a mouse click?
<p>I made a simple FlowChat Editor that creates rectangles and triangles and connects them to each other and shows the way from up to down. I can move this elements on screen too.</p>

<p>I am now trying to create a button to delete the element which I clicked. There is problem that I can delete <code>MyTriangle</code> objects, but I can't delete <code>MyRectangle</code> objects. It deletes but not object which I clicked. I delete from first object to last.</p>

<p>Here is my code:</p>

<pre><code> if (deleteObj) {

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

                }

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

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

                }

            }
        }
</code></pre>

<p><strong>Edit</strong>  Here MyRectangle and MyTriangle classes </p>

<pre><code>public class MyRect extends Ellipse2D.Double {

Point c;
Point in;
Point out;
int posX;
int posY;
int width = 100;
int height = 30;
  int count;


public MyRect(Point center, Point input, Point output,int counter) {

    c = center;
    in = input;
    out = output;
    count=counter;

}

void drawMe(Graphics g) {
    //    in.x=c.x+20;
    int posX = c.x;
    int posY = c.y;
    int posInX = in.x;
    int posInY = in.y;
    int posOutX = out.x;
    int posOutY = out.y;




    g.setColor(Color.MAGENTA);
    g.drawString(" S "+count ,posX-5, posY+5);


    g.setColor(Color.black);
    g.drawRect(posX-50, posY-15, width, height);
    g.setColor(Color.green);
    g.drawRect(posInX-3, posInY-9, 6, 6);
    g.setColor(Color.blue);
    g.drawRect(posOutX-3, posOutY+3, 6, 6);


}
}

public class MyTriangle {

Point c;
Point in ;
Point outYES ;
Point outNO ;
int posX;
int posY;
int count;

public MyTriangle(Point center,Point input,Point outputYES,Point outputNO,int counter)     {

    c = center;
    in = input;
    outYES = outputYES;
    outNO = outputNO;
    count=counter;
}

void drawMe(Graphics g) {

    int posX = c.x;
    int posY = c.y;
    int posInX=in.x;
    int posInY=in.y;
    int posOutYESX=outYES.x;
    int posOutYESY=outYES.y;
    int posOutNOX=outNO.x;
    int posOutNOY=outNO.y;

    int[] xPoints = {posX - 50, posX, posX + 50, posX};
    int[] yPoints = {posY, posY - 30, posY, posY + 30};

     g.setColor(Color.MAGENTA);
    g.drawString(" T "+count,posX-5, posY+5);
    g.setColor(Color.black);
    g.drawPolygon(xPoints, yPoints, 4);
   // draw input
    g.setColor(Color.green);
    g.drawRect(posInX-3,posInY-9, 6, 6);
    g.setColor(Color.blue);
    g.drawRect(posOutYESX-9,posOutYESY-3 , 6, 6);
    g.setColor(Color.red);
    g.drawRect(posOutNOX-3,posOutNOY+3 , 6, 6);
}
}
</code></pre>

<p><strong>Edit 2</strong></p>

<p>Here my funcs to add object to list.Is there could be ant mistake?Because I am her ceratıng new object of that calss and  I am addıng that object to rectlist or trianglelist..</p>

<pre><code>    public void initRect(Point c, Point in, Point out) {
    sCounter++;
    MyRect myrects = new MyRect(c, in, out, sCounter);

    rectsList.add(myrects);
    s_And_t_List.add(myrects);

    objectCounter.add("S " + sCounter);

    selectablePanel.repaint();
}

public void initTriangle(Point c, Point in, Point outYES, Point outNO) {
    tCounter++;
    MyTriangle mytriangles = new MyTriangle(c, in, outYES, outNO, tCounter);

    triangleList.add(mytriangles);
    s_And_t_List.add(mytriangles);
    objectCounter.add("T " + tCounter);
    selectablePanel.repaint();
}
</code></pre>
