JApplet drawing shapes
<pre><code>    import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

@SuppressWarnings("serial")
public class ShapeApplet extends JApplet{
    //contains all shapes that created
    private ShapeContainer shapeContaiter = new ShapeContainer();

    //main window panels
    private Panel leftPanel = new Panel();
    private Panel rightPanel = new Panel();
    private Panel buttomPanel = new Panel();

    //the panel inside right panel
    private Panel shapesPanel = new Panel();

    private String [] shapeNames = {"Cicle","Rect","Polygon","Line","Cylinder"};
    private Choice shapeChoice = new Choice();


    //defines the colors to choose from
    JColorChooser colorChooser = new JColorChooser(Color.BLACK);

    //item that will be use for painting
    private Shape shapeToDraw;

    //creating shapesButtons 
    ImageIcon iconCircle = new ImageIcon("circle.png", "Circle");
    JButton buttonCircle = new JButton(iconCircle);

    ImageIcon iconLine = new ImageIcon("line.png","Line");
    JButton buttonLine = new JButton(iconLine);

    ImageIcon iconRect = new ImageIcon("rect.png","Line");
    JButton buttonRect = new JButton(iconRect);

    ImageIcon iconPolygon = new ImageIcon("polygon.png","Line");
    JButton buttonPolygon = new JButton(iconPolygon);

    //creating the other tool buttons
    JButton buttonClear = new JButton("Undo");

    Checkbox checkBoxIsTheShapeFilled = new Checkbox("Filled");
    //defines the new canvas
    PaintingCanvas paintingCanvas = new PaintingCanvas();
    //defines the class for buttons actions
    ButtonAction buttonAction = new ButtonAction();

    //save the shape that selected
    private int currentTool = 4;
    //integers to keep the mouse location
    private int xPoint1, xPoint2 = 0, yPoint1,yPoint2 = 0;

    @Override
    public void init() {
        System.out.println("points" + xPoint1+yPoint2);
        //setting location , size and properties
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        int screenWidth = (int) dim.getWidth();
        int screenHeight = (int) dim.getHeight();
        this.setSize(screenWidth,screenHeight-400); 
        //setting layout
        this.setLayout(new BorderLayout());

        //creating the choices for  shapes
        for(int i = 0 ; i &lt; shapeNames.length ; i++ )
            shapeChoice.add(shapeNames[i]);

        //defines left Panel and right Panel properties
        this.leftPanel.setBackground(Color.LIGHT_GRAY);
        this.leftPanel.setLayout(new GridLayout(5, 0));

        this.rightPanel.setBackground(Color.LIGHT_GRAY);
        this.rightPanel.setLayout(new BorderLayout());

        //adding items to the right panel
        this.rightPanel.add(colorChooser, BorderLayout.NORTH);

        //setting the shapes panel
        this.shapesPanel.setLayout(new GridLayout(3,3));
        this.shapesPanel.add(buttonCircle);
        this.shapesPanel.add(buttonLine);
        this.shapesPanel.add(buttonRect);
        this.shapesPanel.add(buttonPolygon);
        this.shapesPanel.add(checkBoxIsTheShapeFilled);

        //adding the shapes panel to the right Panel
        this.rightPanel.add(shapesPanel, BorderLayout.SOUTH);

        //adding items to the left panel
        this.leftPanel.add(buttonClear);

        //defines the location of each item on the main window
        this.add(leftPanel, BorderLayout.WEST);
        this.add(rightPanel, BorderLayout.EAST);
        this.add(buttomPanel,BorderLayout.SOUTH);
        this.add(paintingCanvas,BorderLayout.CENTER);   

        //setting button actions
        this.buttonCircle.addActionListener(buttonAction);
        this.buttonLine.addActionListener(buttonAction);
        this.buttonPolygon.addActionListener(buttonAction);
        this.buttonRect.addActionListener(buttonAction);
        this.buttonClear.addActionListener(buttonAction);


    }

    @Override
    public void start() {

        super.start();
    }

    @Override
    public void stop() {

        super.stop();
    }

    @Override
    public void destroy() {

        super.destroy();
    }

    public class PaintingCanvas extends Canvas implements MouseListener, MouseMotionListener
    {
        public PaintingCanvas()
        {
            addMouseListener(this);
        }
        @Override
        public void mouseClicked(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {

        }

        @Override
        public void mouseExited(MouseEvent e) {

        }

        @Override
        public void mousePressed(MouseEvent e) {

            xPoint1 = e.getX();
            yPoint1 = e.getY();
            xPoint2 = e.getX();
            yPoint2 = e.getY();

        }//end of mousePressed


        @Override
        public void mouseReleased(MouseEvent e) {

            xPoint2 = e.getX();
            yPoint2 = e.getY();



            shapeContaiter.add(shapeToDraw);

            System.out.println("Release");
            repaint();

        }


        @Override
        public void update(Graphics g) {
            paint(g);
        }//end of update

        @Override
        public void paint(Graphics g) {

            switch (currentTool)
            {   
                case 0:
                    //System.out.println("Circle pointsxy: " + xPoint1+","+yPoint1);
                    //System.out.println("Circle pointsx2y2: " + xPoint2+","+yPoint2);
                    shapeToDraw = new Circle(xPoint1 , yPoint1, new Point(xPoint2, yPoint2),colorChooser.getColor() , checkBoxIsTheShapeFilled.getState());
                    //System.out.println( "Circle pointsxy: " + shapeToDraw.getLocation());
                    shapeToDraw.draw(g);    

                    break;
                case 1:
                    shapeToDraw = new Line(xPoint1, yPoint1, new Point(xPoint2,yPoint2), colorChooser.getColor(), checkBoxIsTheShapeFilled.getState());
                    shapeToDraw.draw(g);

                    break;
                case 2:

                    break;
                case 3:
                    shapeToDraw = new Rect(xPoint1, yPoint1, new Point(xPoint2, yPoint2), colorChooser.getColor(), checkBoxIsTheShapeFilled.getState());
                    shapeToDraw.draw(g);

                    break;
                case 4:
                    break;
                default:
            }//end of switch

            System.out.println("Size of shapeContianer: "+shapeContaiter.size());
            System.out.println("pointsxy: " + xPoint1+","+yPoint1);
            System.out.println("pointsx2y2: " + xPoint2+","+yPoint2);


        }//end of paint
        @Override
        public void mouseDragged(MouseEvent e) {


        }
        @Override
        public void mouseMoved(MouseEvent e) {
            // TODO Auto-generated method stub

        }

    }//end of canvas

    public class ButtonAction implements ActionListener
    {

        @Override
        public void actionPerformed(ActionEvent e) {

            if ( e.getSource() == buttonCircle)
                currentTool = 0;
            else if ( e.getSource() == buttonLine)
                currentTool = 1;
            else if ( e.getSource() == buttonPolygon)
                currentTool = 2;
            else if ( e.getSource() == buttonRect)
                currentTool = 3;
            else if (e.getSource() == buttonClear){
                currentTool=4;
                if(shapeContaiter.isEmpty()) JOptionPane.showMessageDialog(buttonClear, "Nothing to delete");
                else {

                    Graphics g = paintingCanvas.getGraphics();

                    shapeContaiter.get(shapeContaiter.size()-1).setColor(Color.WHITE);
                    shapeContaiter.get(shapeContaiter.size()-1).draw(g);
                    shapeContaiter.remove(shapeContaiter.size()-1);

                    System.out.println("Size of shapeContianer: "+shapeContaiter.size());
                }
            }


        }//end of action performed

    }//end of ButtonClicked

}
</code></pre>

<p>I'm trying to create an Undo button that will erase the last shape from the shapeContainer array and from the canvas.
i can put the finger on the problem but when i am trying to erase on of the shapes it erase the shape that i painted before the current shape.</p>

<p>i created Circle,Rect,Polygon,Line classes that after heavy checking seems to be ok.</p>
