Capturing Screen using java

Hi,
Is there anyway I can do a printscreen using java and then send the image over the network?
axlrose82

hi,
I'm using java.awt.robot to do a print screen and trying to save the image or sending it over the network.
I tried to use applets but I got a "XTEST extension not installed on this X server: Error 0". Have you any idea how I can get around this?
Thanks for the help.
Sri.
My code for the applet is as follows:
import java.io.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Robot;
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import java.awt.Image.*;
import java.awt.image.BufferedImage;
import javax.imageio.*;
import javax.imageio.stream.FileImageOutputStream;
import java.util.*;
public class CaptureScreen extends JFrame{
JButton button1 = new JButton("ScreenCapture");
JButton button2 = new JButton("Quit");
Image img = null;
JFrame jframe = null;
JLabel jl = null;
ActionListener al = new ActionListener(){
     public void actionPerformed(ActionEvent e){
          String id = ((JButton)e.getSource()).getText();
          if(id.equals("ScreenCapture")){
          System.out.println("Screen capture button pressed");
          getImage();
          else if(id.equals("Quit")){
          jframe.dispose();
          System.exit(0);
public void getImage(){
     System.out.println("Getting Image");
     try {
     Robot robot = new Robot();
     // Capture the whole screen
     area = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
     BufferedImage bufferedImage = robot.createScreenCapture(area);
     Image image = toImage(bufferedImage);
     jl.setText("get image");
     try
          { // this try set turns the image into a jpg that is saved to the hard drive in the program dir.
          FileOutputStream output = new FileOutputStream("Screen.jpg");
          JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(output);
          encoder.encode(bufferedImage);
          output.flush();
          output.close();
     catch(IOException e)
     catch (AWTException awte) {
     awte.getMessage();
     //repaint();
// This method returns an Image object from a buffered image
public static Image toImage(BufferedImage bufferedImage) {
return Toolkit.getDefaultToolkit().createImage(bufferedImage.getSource());
public void paint(Graphics g){
public void Startproc(){
     Container cp = getContentPane();
     jframe = new JFrame();
     jframe.setSize(500,500);
     jframe.setLocation(10,100);
     JPanel jp1 = new JPanel();
     JPanel jp2 = new JPanel();
     jl = new JLabel("Hello");
     cp.setLayout(new FlowLayout());
     button1.addActionListener(al);
     button2.addActionListener(al);
     jp1.add(button1);
     jp1.add(button2);
     jp2.add(jl);
     cp.add(jp1);
     cp.add(jp2);
public static void main(String[] args){
     CaptureScreen capturescr = new CaptureScreen();
     capturescr.Startproc();
     capturescr.setSize(500,500);
     capturescr.setVisible(true);

Similar Messages

  • Clearing the screen using java

    hi
    how to clear the screen using a java program

    for (int n = 0; n < 24; n++) System.out.println();
    Even better: don't clear the screen. The program I ran before your program printed out very important things. If your program throws away those important things then I will not like you or your program.

  • Clearing screen using java

    In java, how can i clear the console screen while running the program?

    It depends on what you mean by "using Java". There are Java libraries to do screen control.
    Of course, there are different kinds of consoles, and some can't be cleared at all.

  • How need to take screen shot of the screen using java.awt.Robot from javafx

    1) I am displaying a Stage which is having an image and shapes in it and wanted to take the screen shot as and when i move the shape( which moves the stage ).
    I am trying to java.awt.Robot, but i am getting headless exception. I used
    @Override
    public void start(final Stage primaryStage) {
    // creating some images and shapes
    Platform.runLater(new Runnable() {
    @Override
    public void run() {
    // update();
    public void update() {
    if (stg.isShowing()) {
    ScreenCapture.capture(stg.getX() + 2, stg.getY() + 2, (int) boundsOfCircle.getBoundsInParent().getWidth(), (int) boundsOfCircle.getBoundsInParent().getHeight());
    magnifierImageView.setImage(new Image(SCREEN_SHOT_FILE));
    public static void capture(final double x, final double y, final int width, final int height) {
    EventQueue.invokeLater(new Runnable() {
    public void run() {
    try {
    System.out.println("x ="+x +" y = "+y +" width "+width +" height ="+height);
    Robot robot = new Robot();
    } catch (Exception e) {
    System.out.println("exception arised while taking the screen shot ");
    e.printStackTrace();
    The above code throws headless exception.
    2) The second issues is have a image & i am dividing the image into different rows and cols( images of same size ). This is i am doing using awt. and i wanted to load those different images into
    javafx images . I am facing the issues when i try to load the images into javafx.

    hi,
    click on print screen button in your keyboard.
    open a word document and do Ctrl V .
    *Reward points if it helped

  • Secure key wont show up on screen using java

    My secure key isn't working with my java even though java is up to date

    Try a reset and see if that makes it appear.
    Reset the iPad by holding down on the sleep and home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider if it appears on the screen - let go of the buttons. Let the iPad start up.

  • How to create a Full screen in Java

    Could some one help me in creating a full screen using Java such that we dont see any Taskbar or anything that is related to windows. For eg when we play a game we dont have access to those windows components.
    The basic question is How to Lock the Desktop using Java Program and also how to capture the Key events Ctrl + Alt + Del and Alt + Tab and disable its actual functionality or change its action..

    Could some one help me in creating a full screen
    using Java such that we dont see any Taskbar or
    anything that is related to windows. For eg when we
    play a game we dont have access to those windows
    components. http://onesearch.sun.com/search/onesearch/index.jsp?qt=full+screen+java&subCat=&site=dev&dftab=&chooseCat=javaall&col=developer-forums
    The basic question is How to Lock the Desktop using
    Java Program and also how to capture the Key events
    Ctrl + Alt + Del and Alt + Tab and disable its
    actual functionality or change its action..You can't.

  • Capturing Signatures using JavaMediaFrameWork

    I want the code for capturing signature using java (JMF)
    if a signature is signed in the signature pad we have to capture that signature and store it in the database after that we also verify that signature present in database
    I want to know which technology to use in java and a sample code for that one

    Hi,
    Please translate your description to English language to help us understand.
    In addition, this forum is to discuss the problems about the development of desktop Office applications such as VBA, VSTO, Apps for Office .etc. But I think your question is related to the end-user feature of Access in Surface.
    For more efficient responses, I suggest you posting it in
    Surface Community or
    Office Community with English language.
    Thanks.
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Captivate fails to capture screen

    Hi,
    I need some help in understanding why on certain applications
    Captivate fails to :-
    Capture drop down menus
    and on the same application the "printscreen" function seems
    not to work.
    The application I'm trying to capture is Latent Zero.
    Thanks
    Tom.

    Hello Tom,
    What version of Captivate are you using? I have experienced
    these sorts of problems when attempting to capture screens using an
    application viewer program such as Real VNC with Captivate 1 but
    this one was addressed in Adobe Captivate 2
    Regards,
    Mark

  • How to capture output of java files using Runtime.exec

    Hi guys,
    I'm trying to capture output of java files using Runtime.exec but I don't know how. I keep receiving error message "java.lang.NoClassDefFoundError:" but I don't know how to :(
    import java.io.*;
    public class CmdExec {
      public CmdExec() {
      public static void main(String argv[]){
         try {
         String line;
         Runtime rt = Runtime.getRuntime();
         String[] cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E.java";
         Process proc = rt.exec(cmd);
         cmd = new String[2];
         cmd[0] = "javac";
         cmd[1] = "I:\\My Documents\\My file\\CSM\\CSM00\\SmartQ\\src\\E";
         proc = rt.exec(cmd);
         //BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
         BufferedReader input = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
         while ((line = input.readLine()) != null) {
            System.out.println(line);
         input.close();
        catch (Exception err) {
         err.printStackTrace();
    public class E {
        public static void main(String[] args) {
            System.out.println("hello world!!!!");
    }Please help :)

    Javapedia: Classpath
    How Classes are Found
    Setting the class path (Windows)
    Setting the class path (Solaris/Linux)
    Understanding the Java ClassLoader
    java -cp .;<any other directories or jars> YourClassNameYou get a NoClassDefFoundError message because the JVM (Java Virtual Machine) can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.
    javac -classpath .;<any additional jar files or directories> YourClassName.javaYou get a "cannot resolve symbol" message because the compiler can't find your class. The way to remedy this is to ensure that your class is included in the classpath. The example assumes that you are in the same directory as the class you're trying to run.

  • I'm trying to record only part of my screen using my Quicktime 10.0, but once I press record in the "Screen recording" feature it automatically starts recording and doesn't give me the option to choose what part of the screen to capture. What gives?

    I'm trying to record only part of my screen using my Quicktime 10.0, but once I press record in the "Screen recording" feature it automatically starts recording and doesn't give me the option to choose what part of the screen to capture. What gives?

    QuickTime version 10 can only record the entire screen.
    10.1, 10.2 and 10.3 offer part of the screen recording.

  • I have been using GRAB to capture screen displays.  It has just stopped working since the last OSX Upgrade.  Can anyone, please help restore functionality?

    I have been using GRAB to capture screen displays.  It has just stopped working since the last OSX Upgrade.  Can anyone, please help restore functionality?

    Thanks for that.  I did as suggested but when I tried again, it still did not work.  Another  com.apple.Grab.plist appeared in the Library.
    I now have the following files in Library
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.LSSharedFil eList.plist
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.LSSharedFil eList.plist.lockfile
    file://localhost/Users/peterpatel/Library/Preferences/
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.plist.lockf ile
    What do you suggest I do now?

  • Screen capture error, using "ctrl command shift 4"

    when I captured the screen using "ctrl command shift 4", the captured picture is cracked. but when using "command shift 4", the captured picture is fine.
    like below
    How can I fix it?

    use CMD  Shift 4
    better still use a FREE screen capture APP like ducklink
    http://www.ducklink.com/p/free-screen-capture-tool-on-mac/
    Best one is the APP SnapNDrag I use all the time.
    http://download.cnet.com/SnapNDrag/3000-2094_4-40913.html

  • Can i capture and record a youtube video that is playing on my screen using quicktime?

    How can i capture and record a youtube video that is playing on my screen using quicktime?

    Hi Paul, QuickTime X can record video and here is the tutorial for you: http://support.apple.com/kb/PH5882?viewlocale=en_US. I'm wondering why you don't just download it using some free YouTube downloader, easy and fast.

  • Capturing audio through applet using Java Sound

    hi fellows i need ur help.
    I am working on a voice project to Capture & Play the sound using java sound API instead of JMF. I can capture , play and transmit the sound through application. It works pretty fine but when i convert it to the applet, it is not working.
    I got the full system permissions and also signed the applet for Internet Explorer. Also i packed the
    javax.sound.midi.*
    javax.sound.sampled.*
    classes in the signed cab.
    After doing all this i am getting the AudioFormat not supported exception. I changed the format and used all the combinations but still getting this error
    No line matching interface TargetDataLine supporting format PCM_SIGNED, 16000.0 Hz, 16 bit, mono, big-endian, audio data is supported.
    java.lang.IllegalArgumentException: No line matching interface TargetDataLine supporting format PCM_SIGNED, 16000.0 Hz, 16 bit, mono, big-endian, audio data is supported.
         at javax/sound/sampled/AudioSystem.getLine (AudioSystem.java:312)
         at com/vsoft/voice/VoiceRecord.run (VoiceApplet.java:93)
         at java/lang/Thread.run (Thread.java)plz help me to sort out this problem.

    plz have a look over this problem

  • How to take a screen shot using Java

    I'd like to get a screenshot while a user is playing a game such as Quake or Half-life. Is this at all possible using Java or do I have to stupe to using OS dependent functions?
    Matt

    In SDK 1.3 there's a createScreenCapture method in the java.awt.Robot class.

Maybe you are looking for