title: Java - Erasing with Line2D
body: <p>I have created a simple paint program in java. I have run into a problem with the erasing tool. I can not allow the user to just paint with white paint to erase, because I want the background to be a picture. Anyway, I am trying to go about this by whenever the user draws with paint, trying to make it add a Line2D to an Array List. Then, I want the user to draw a white line on the program to show what is being erased. When the white line comes into a graphic, I want to get a result. Here's my code:</p>
  
  <pre><code> al = new ArrayList&lt;Line2D&gt;();
  
  
      addMouseMotionListener(new MouseMotionAdapter(){
          public void mouseDragged(MouseEvent e){
  
              if(graphics2D != null &amp;&amp; paint.erase==false)
              {
                  currentX = e.getX();
                  currentY = e.getY();
                  graphics2D.setStroke(new BasicStroke(size));
              graphics2D.drawLine(oldX, oldY, currentX, currentY);
  
  
              repaint();
              oldX = currentX;
              oldY = currentY;
  
  
  
          Line2D test=new Line2D.Float(oldX, oldY, currentX, currentY);
  
          al.add(test);
              //New system
  
          }
              if (paint.erase==true)
              {
                  currentX = e.getX();
                  currentY = e.getY();
                  graphics2D.setStroke(new BasicStroke(size));
                  graphics2D.drawLine(oldX, oldY, currentX, currentY);
  
                  repaint();
  
  
  
                  for( Line2D name : PadDraw.al ) {
                      boolean result = Line2D.linesIntersect(oldX,oldY,currentX,currentY,name.getX1(),name.getY1(),name.getX2(),name.getY2());
                      if (result==true)
                      {
                          System.out.println("paint found");
                      }
                      }
  
  
                  oldX = currentX;
                  oldY = currentY;
              }
  
          }
          });
  </code></pre>