unable to capture screen

help, i can’t make this code works :’(

mainFrame.paint(captured.createGraphics());

the captured image only show gray color :-/
any other way to screen capture?

screen capture method:


      Image captured;
      public Image captureScreen() {
            captured = mainFrame.createImage(640,480);
            mainFrame.paint(captured.getGraphics());
            return captured;
      }

my game rendering loop using mainFrame Graphics:


      private final void doRender() {
            //mainFrame.repaint();
            rendering(mainFrame.getGraphics());      // using mainFrame graphics
            }
      }

      private final void rendering(Graphics g) {
            if (offScreen == null ||
                  offScreen.validate(mainFrame.getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {
                  // create double buffering
                  offScreen = mainFrame.createVolatileImage(appDimension.width, appDimension.height);
                  offScreenGfx = offScreen.createGraphics();
            }
            render(offScreenGfx);
            g.drawImage(offScreen, 0, 0, mainFrame);      // draw to screen
      }

      private final void render(Graphics g) {
            // paint the game
      }

Not sure this is the answer but it looks like you are calling
mainFrame.paint()

but all of your drawing code is in mainFrame.render()

What is .paint() doing? does it call .render()?