java - draw a rectangle over an image -


i have tried code below drawing rectangle on image(jlabel) not drawing. please solve this.

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 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);      }                                     

you have infinite recursion there, , stack overflow. this:

this.paintcomponent(g) 

should instead:

super.paintcomponent(g); 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -