title: JAVA Draw line with swt not deleting previous lines
body: <p>I have an application where onMouseDown starts drawing a line and the line is drawn when onMouseUp. The problem I have is that when I move my mouse the previous lines stays. How can I do it to work normally and when the line is drawn, the previous are deleted?
  To get it more clear I'm posting a screanshots: 
  <img src="https://i.stack.imgur.com/d9wCt.png" alt="1"></p>
  
  <p><img src="https://i.stack.imgur.com/TSl9o.png" alt="2"></p>
  
  <p>And here is my code:</p>
  
  <pre><code>public class MainClass {
  
      private static Point fp;
  
      private static Point lp;
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          Display d = new Display();
          Shell shell = new Shell(d);
  
          shell.setLayout(new FillLayout());
          Canvas c = new Canvas(shell, SWT.NONE);
          c.setSize(100, 100);
          c.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
  
          shell.open();
  
          createPaintListener(c);
          createMouseListener(c);
          createMoveListener(c);
          while(!shell.isDisposed()) {
              if(!d.readAndDispatch()) {
                  d.sleep();
  
              }
          }
  
          d.dispose();
      }
  
      private static void createMoveListener(final Canvas c) {
          // TODO Auto-generated method stub
          c.addMouseMoveListener(new MouseMoveListener() {
  
              @Override
              public void mouseMove(MouseEvent e) {
                  // TODO Auto-generated method stub
                  if (fp != null) {
                      GC gc = new GC(c);
                      if(lp != null) {
                          gc.setXORMode(true);
                          gc.drawLine(fp.x, fp.y, lp.x, lp.y);
  
                          lp = new Point(e.x, e.y);
                          gc.drawLine(fp.x, fp.y, lp.x, lp.y);
                      }else {
                          lp = new Point(e.x, e.y);
                      }
  
                      gc.dispose();
                  }
              }
          });
      }
  
      private static void createMouseListener(final Canvas c) {
          c.addMouseListener(new MouseListener() {
  
              @Override
              public void mouseDoubleClick(MouseEvent e) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void mouseDown(MouseEvent e) {
                  // TODO Auto-generated method stub
                  if (fp == null) {
                      fp = new Point(e.x, e.y);
                  } else {
  
                  }
              }
  
              @Override
              public void mouseUp(MouseEvent e) {
                  // TODO Auto-generated method stub
                  GC gc = new GC(c);
                  gc.drawLine(fp.x, fp.y, e.x, e.y);
                  gc.dispose();
                  fp = null;
              }
  
          });
  
      }
  
      private static void createPaintListener(Canvas c) {
          c.addPaintListener(new PaintListener() {
  
              @Override
              public void paintControl(PaintEvent e) {
                  // TODO Auto-generated method stub
              }
          });
      }
  
  }
  </code></pre>