我尝试过以下代码在图像上绘制一个矩形(jLabel),但它不是绘图。请帮忙解决这个问题。
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);
}
答案 0 :(得分:2)
你有无限递归,并且会出现堆栈溢出。 这样:
this.paintComponent(g)
应该是:
super.paintComponent(g);