What method can this be implemented? Redrawing should be prohibited for a specific instance of a class, and not for the entire class.
I'll tell you the situation. I create multiple instances of the Graph class. When I create a new instance, I call repaint() and update(getGraphics()) . In this case, all the old objects are redrawn by the parameters of the new, and I do not need it. How to prohibit their redrawing?
UPD: Found that when you call update (getGraphics ()), another Graph instance is created. Why it happens?
Code:
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; g2d.setStroke(new BasicStroke(3)); colIndex++; Color c = Color.black; switch(colIndex){ case 0: {c = Color.red;break;} case 1: {c = Color.orange;break;} case 2: {c = Color.green;break;} case 3: {c = Color.CYAN;break;} case 4: {c = Color.blue;break;} case 5: {c = Color.MAGENTA;break;} case 6: {c = Color.black;break;} case 7: {c = Color.red;colIndex = 0;break;} } g2d.setColor(c); int GrX1=0; int GrY1=0; int GrX2; int GrY2; for(int i1 = 0;i1<(GraphDrawer.x2-GraphDrawer.x1);i1++) { switch (funcvar) { case 'x': {varvalue = (double) -10 + i1*GraphDrawer.xUnit;break;} case 'y': {varvalue = (double) -10 + i1*GraphDrawer.yUnit;break;} } switch (funcvar) { case 'x':GrX2 = (int) Math.round((result+10)*21); GrY2 = (int) Math.round((-varvalue+10)*21); if (GrX1!=0||GrY1!=0){ g2d.drawLine(GrX1,GrY1,GrX2,GrY2); } GrX1 = GrX2; GrY1 = GrY2; break; case 'y':GrX2 = (int) Math.round((varvalue+10)*21); GrY2 = (int) Math.round((-result+10)*21); if (GrX1!=0||GrY1!=0){ g2d.drawLine(GrX1,GrY1,GrX2,GrY2); } GrX1 = GrX2; GrY1 = GrY2; break; } } }