我有一个表单,在鼠标点击事件上画椭圆。这对我很有效。圆圈被绘制出来了。但是当我最小化表单并再次将其最大化时,面板会刷新并且圆圈会被删除(即面板变成空白)。
代码如下: 我有一个JFrame,在上面有一个名为jPanel1的Jpanel,在此面板上绘制圆圈。
private void jPanel1MouseClicked(java.awt.event.MouseEvent evt) {
count += 1;
if (count <= clients) {
drawCircle(evt.getX() - (radius / 2), evt.getY() - (radius / 2));
}
}
public void drawCircle(int x, int y) {
Graphics g = jPanel1.getGraphics();
g.drawOval(x - radius, y - radius, 2 * radius, 2 * radius);
g.setColor(Color.BLACK);
g.fillOval(x - radius, y - radius, 2 * radius, 2 * radius);
}