title: take snapshot of full JFrame and Jframe only
body: <p>Heys guys, I've developped a code to take a screen shot of my whole screen, but I want it to take the screen shot of only the things inside my Jframe. Ill be using it to print the image later on by the way. And one of the main problem is, the mouse also comes inside the snapshot. I don't want the mouse or the two buttons at the bottom. I can just change visi of buttons but what should be done for mouse and inside Jframe only shot? Here is my code it takes screen shot of whole screen.</p>
  
  <pre><code>                try{
                  Thread.sleep(1000);
                  Toolkit tk = Toolkit.getDefaultToolkit(); //Toolkit class                         returns the default toolkit
                  Dimension d = tk.getScreenSize();
  
  //Dimension class object stores width &amp; height of the toolkit screen
  // toolkit.getScreenSize() determines the size of the screen
  
                  Rectangle rec = new Rectangle(0, 0, d.width, d.height);  
  //Creates a Rectangle with screen dimensions,         
  
                  Robot ro = new Robot(); //to capture the screen image
                  BufferedImage img = ro.createScreenCapture(rec);
  
  
  
                  File f;
                  f = new File("myimage.jpg"); // File class is used to write the above generated buffered image to a file
                  ImageIO.write(img, "jpg", f);
  
              } catch (Exception ex) {
                  System.out.println(ex.getMessage());
              }
  </code></pre>