public void paintComponent(Graphics g2) {
    int w = getWidth();
    int h = getHeight();
    if ((img == null) || (img.getWidth(null) != w) || (img.getHeight(null) != h)) {
      img = createImage(w, h);

      Graphics g = img.getGraphics();
      for (int x = 0; x <= w / 1; x++) {
        for (int y = 0; y <= h / 1; y++)
          g.drawImage(bgImage, x, y, null);
      }
      if ((g instanceof Graphics2D)) {
        Graphics2D gg = (Graphics2D)g;

      }
      g.dispose();
    }
    g2.drawImage(img, 0, 0, w, h, null);
  }