public Line2D find_Line(Point2D p) { for(int i = 0; i < lines.size(); i++) { Line2D l = (Line2D) lines.get(i); if(l.contains(p)) { return l; } } return null; } public void remove_Line(Line2D line) { if(line == null) return; if(line == this.line) this.line = null; lines.remove(line); repaint(); } public void mouseClicked(MouseEvent e) { if(e.getClickCount() >= 2) { current = find(e.getPoint()); one_press = false; current2 = null; if (current != null) { remove(current); } else { line = null; line = find_Line(e.getPoint()); if(line != null) { remove_Line(line); } } } } public void mouseMoved(MouseEvent e) { if(find(e.getPoint()) == null && find_Line(e.getPoint()) == null) setCursor(Cursor.getDefaultCursor()); else setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR)); } public void paint(Graphics g) { super.paintComponents(g); Graphics2D g2 = (Graphics2D) g; for(int i = 0; i < circle.size(); i++) { g2.setColor(new Color(10, 170 , 133)); g2.draw((Ellipse2D) circle.get(i)); g2.setColor(new Color(250 , 110 , 50)); g2.drawString(iterator.get(i).toString() , (float)((Ellipse2D) circle.get(i)).getCenterX() , (float)((Ellipse2D) circle.get(i)).getCenterY()); } for(int i = 0; i < lines.size(); i++) { g2.setColor(new Color(10, 170 , 133)); g2.setStroke(new BasicStroke(5)); g2.draw((Line2D) lines.get(i)); } } Good day! I want to remove the drawn line by double-clicking the mouse. When you move to a line, the cursor does not change to a cross. These lines are drawn between circles (work on graph theory). All the lines I store in ArrayList.
I found the line like this: I looked at the place of the click and checked the entry with contains. I think that it is in the contains ... I can throw off all the code.