title: draw a rectangle over an image
body: <p>I have tried the code below for drawing a rectangle on an image(jLabel) but its not drawing. Please help to solve this.</p>
  
  <pre><code>protected void paintComponent(Graphics g)
  {
  
     this.paintComponent(g);
     g2 = (Graphics2D) g;
  
     g.drawRect(n,n1,40,40);
  
  }
  
  
  
  private void jLabel1MouseClicked(java.awt.event.MouseEvent evt)   
  {                                     
      // TODO add your handling code here:
      k=0;
      f=jLabel1.getMousePosition();
      n=f.x;
      n1=f.y;
      n=n+p/2;
      n1=n1+(q/2-25);
      repaint(n,n1,40,40);     
  }                                    
  </code></pre>