This tutorial provides you with code to capture a screen shot using java. You can capture a part of screen or the whole screen as well. Just copy the below code and save the file as ScreenShotPanel.java compile and run it using java SDK.
if every thing works as excepted then you will see a similar window as below.
import java.awt.*; import javax.swing.*; /** * * @author Originative */ class ScreenShotPanel extends JPanel{ Image screenShot=null; Rectangle area = null; private Image image; public ScreenShotPanel(){ JLabel imagePanel=new JLabel(); // Capture a particular area on the screen // int x = 100; // int y = 100; // int width = 400; // int height = 400; // area = new Rectangle(x, y, width, height); // screenShot=ScreenShotPanel.captureImage(area); // Capture the whole screen area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()); screenShot=ScreenShotPanel.captureImage(area); } public static Image captureImage(Rectangle area){ Image img=null; try{ Robot robot = new Robot(); img = (Image)robot.createScreenCapture(area); } catch(Exception e){ System.out.println(e); } return img; } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(screenShot, 0, 0, null); } public static void main(String []nix){ ScreenShotPanel screenShotPanel=new ScreenShotPanel(); JFrame screenShotFrame=new JFrame(); screenShotFrame.add(screenShotPanel); screenShotFrame.setSize(800, 800); screenShotFrame.setVisible(true); screenShotFrame.setTitle("Capturing a Screen Shot - Tutorial Jinni"); screenShotFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
if every thing works as excepted then you will see a similar window as below.
1 comments:
Easy "water hack" burns 2 lbs OVERNIGHT
At least 160 000 women and men are using a easy and SECRET "water hack" to lose 1-2lbs every night as they sleep.
It's painless and works on everybody.
Just follow these easy step:
1) Hold a clear glass and fill it up half full
2) Then follow this weight loss HACK
and you'll be 1-2lbs lighter as soon as tomorrow!
Post a Comment