Hi there,
I want to implement undo logic which deletes the last drawn shape. To test this logic i had cleared shapes list and redrawn all shapes but still last shape does not delete.
public void drawAllShapes(Graphics2D g)
{
//draw all triangles
for (DrawTriangle t : newTriangles)
{
t.drawTriangle(g);
}
for(DrawRect r: rectangles)
{
r.drawRectangle(g);
}
//draw all circles
for (DrawCircle c : circles)
{
c.drawEllipse(g);
}
System.out.println("Rect size: " +rectangles.size());
System.out.println("Circle size: " +circles.size());
}//end drawAllShpapes
//undo logic
@Override
public void paintComponent(Graphics graphics){
Graphics2D graphics2d = (Graphics2D)graphics;
if(UndoCommand.undoPressed) {
rectangles.clear();
drawAllShapes(g);
UndoCommand.undoPressed = false;
}
}
Please tell me what I am doing wrong here. Thanks !