title: Using SWT and canvas, Moving line drawn with button
body: <p>I come to you in time of need once again. hehehe Ive done a little SWT which makes lines, circles, squares and triangles. I do this by taking the start point and the end point to draw all of these figures. once drawn I want to move it in x and y axis. Ill put here the core of where im having trouble. Im maing the lines by having a mouse listener inside the canvas, and hearing when i clicks down and lets go the click.
  //This is the listener</p>
  
  <p>MasX.addListener(SWT.Selection, new Listener(){</p>
  
  <pre><code>        public void handleEvent(Event event) {
              SX += 1;
              EX += 1;
              canvas.redraw();
              //gc.drawLine(SX, SY, EX, EY);
              //crearLinea(SX,SY,EX,EY,gc);
  
          }
  
      });
  </code></pre>
  
  <p>//This is  the line drawing method</p>
  
  <pre><code>public void crearLinea(int SX, int SY, int EX, int EY, GC gc){
  
      int x1 = SX;
      int x2 = EX;
      int y1 = SY;
      int y2 = EY;
      System.out.println(SX+" "+SY+" "+EX+" "+EY);
      int cont = 0;
      float dx, dy, m, y, x;
      if (x1&gt;x2){
          int ax = x2;
          int ay = y2;
          x2 = x1;
          x1 = ax;
          y2 = y1;
          y1 = ay;
      }
      dx = x2 - x1;
      dy = y2 - y1;
      m = dy/dx;
      if (m&gt;=-1&amp;&amp;m&lt;=1){
          y = y1;
          //System.out.println(m+" "+x1+" "+y1+"....."+x2+" "+y2);
          for (x = x1 ; x &lt;= x2;x=x+5){
              //if (x&gt;=dot&amp;&amp;x&lt;=dot+10||x&gt;=dot*2&amp;&amp;x&lt;=dot*2+10||x&gt;=dot*3&amp;&amp;x&lt;=dot*3+10){
                  gc.drawLine((int)x, (int)Math.round(y), (int)x, (int)Math.round(y));
                  y+=m*5;
              //}
          }   
      }
      if(m&gt;1){
          x = x1;
          //System.out.println(m+" "+x1+" "+y1+"....."+x2+" "+y2);
          for (y = y1 ; y &lt;= y2;y=y+3){
              if (cont&lt;=5){
              //System.out.println(cont);
              gc.drawLine((int)Math.round(x), (int)y, (int)Math.round(x), (int)y);
              cont++;
              }
              if(cont&gt;=10){
              //System.out.println(cont);
              cont=0;
              }
              if(cont&gt;5){
              //System.out.println(cont);
              cont++;
              }
              x+=(1/m)*3; 
          }
      }
      if(m&lt;-1){
          x = x1;
          //System.out.println(m+" "+x1+" "+y1+"....."+x2+" "+y2);
          for (y = y1 ; y &gt;= y2;y--){
              if(y%10==0||y%8==0||y%12==0){
              gc.drawLine((int)Math.round(x), (int)y, (int)Math.round(x), (int)y);
              }
              x-=(1/m);   
          }
      }
  
  }
  </code></pre>
  
  <p>The error it gives me is Null pointer exception and points to the gc.drawline() </p>
  
  <p>Hope someone can help me :D </p>