@Override
    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
                
        // draw the point rectangles
        Point p;
        for (int i = 0; i < polypoints.size(); i++)
        {
            p = polypoints.get(i);
            g.fillRect(p.x - POINTSIZE2, p.y - POINTSIZE2, POINTSIZE, POINTSIZE);
        }
        
        // draw the connecting lines
        if (polypoints.size() < 1) return;
        Point p2;
        for (int i = 0; i < polypoints.size() - 1; i++)
        {
            p = polypoints.get(i);
            p2 = polypoints.get(i+1);
            g.drawLine(p.x, p.y, p2.x, p2.y);
        }
        
        // draw triangles if they are already calculated
        if (triangles != null)
        {
            g.setColor(Color.BLUE);
            for (int i = 0; i < triangles.size(); i++)
                triangles.get(i).draw(g);
        }
        
        
        // if polygon is completed, draw line from last to first point and work is done
        if (this.isPolyClosed) 
        {
            g.drawLine(polypoints.get(polypoints.size() - 1).x, polypoints.get(polypoints.size() - 1).y, 
                       polypoints.get(0).x, polypoints.get(0).y);
            return;
        }
        
        // draw current line
        g.drawLine(polypoints.lastElement().x, polypoints.lastElement().y, mouseX, mouseY);
        
        // draw string to close line
        if ( (polypoints.size() > 2) && 
             (Math.abs(mouseX - polypoints.firstElement().x) < 5) &&
             (Math.abs(mouseY - polypoints.firstElement().y) < 5) )
        {
            g.drawString("Closing polygon", mouseX + 5, mouseY + 5);
        }
    }