public void drawPages() {

    // loop through pages
    for (int i = 0; i < pages.size(); i++) {
      // load the page
      Page p = pages.get(i);

      try {
        g2d.setTransform(identity);
      }
      catch (NullPointerException e) { }
      // check if page is being shown
      if (p.getVisible()) {
        try {
          p.paint(g2d);
        }
        catch (NullPointerException e) { }
      }
    }
  }