public static void onRepaint(Graphics g) {
        try {
            Iterator<PComponent> it = components.iterator();
        while(it.hasNext()) {
            PComponent comp = it.next();
            if(comp == null)
                continue;
                if (shouldDraw) {
                    if (comp.shouldPaint()) {
                        Font oldFont = g.getFont();
                        Color oldColor = g.getColor();
                        comp.repaint((Graphics2D) g);
                        g.setFont(oldFont);
                        g.setColor(oldColor);
                    }
                }
                else {
                    if (comp instanceof PFrame) {
                        for (PComponent component : ((PFrame) comp).getComponents())
                            if (component.forcePaint()) {
                                Font oldFont = g.getFont();
                                Color oldColor = g.getColor();
                                component.repaint((Graphics2D) g);
                                g.setFont(oldFont);
                                g.setColor(oldColor);
                            }
                    }
                    else if (comp.forcePaint()) {
                        Font oldFont = g.getFont();
                        Color oldColor = g.getColor();
                        comp.repaint((Graphics2D) g);
                        g.setFont(oldFont);
                        g.setColor(oldColor);
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }