Pages

Java print screen

Complete source code below will show you, how to implement print screen or capture screen image in java. Program below will capture screen during it's executing time and after that, it will paint the image on a canvas before add it into a JFrame to display it's result.

*************************************************************
COMPLETE SOURCE CODE FOR : CaptureScreen.java
*************************************************************


import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.Canvas;
import java.awt.Graphics;

import java.awt.image.BufferedImage;

import javax.swing.JFrame;

public class CaptureScreen extends Canvas
{
Rectangle screenRectangle=new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());

Robot myRobot;

BufferedImage screenImage;

public CaptureScreen()
{
try
{
myRobot=new Robot();
}
catch(Exception exception)
{
exception.printStackTrace();
}

screenImage=myRobot.createScreenCapture(screenRectangle);

JFrame myFrame=new JFrame("Capture Screen");

myFrame.add(this);

myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);
myFrame.setVisible(true);
}

public void paint(Graphics g)
{
g.drawImage(screenImage,0,0,this);
}

public static void main(String[]args)
{
CaptureScreen cs=new CaptureScreen();
}
}


*************************************************************
JUST COMPILE AND EXECUTE IT
*************************************************************
Related Posts Plugin for WordPress, Blogger...

I Also Can Create T-Shirt Logo For You