Java, Ruby, JRuby, JRubify some Java?

A

Audrey A Lee

Hello JRuby People,

I'm not quite ready to JRubyify yet but,
I'm working on a mini-project which requires that I screen-capture a
portion of my x-display on a linux box.

It looks like I can use a class in Java named "Robot" to do this:
- http://java.sun.com/javase/6/docs/api/java/awt/Robot.html

I figure any class (even if it is a Java class) named "Robot" deserves
my attention.

So I ran this query:
- http://www.google.com/search?q=java+robot+screencapture

And this page looks good:
- http://www.rgagnon.com/javadetails/java-0489.html

I see this example:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

class ScreenCapture {
public static void main(String args[]) throws
AWTException, IOException {
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize
()) );

// Save as JPEG
File file = new File("screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);

// Save as PNG
// File file = new File("screencapture.png");
// ImageIO.write(screencapture, "png", file);
}
}

My question:
Is it possible to transform the above Java-syntax into Ruby-syntax
which could be interpreted by JRuby?

Or I could ask it this way:
How do I transform the above Java-syntax into JRuby-syntax?

--Audrey
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Wed, 23 Sep 2009 15:25:11 +0900
Von: Audrey A Lee <[email protected]>
An: (e-mail address removed)
Betreff: Java, Ruby, JRuby, JRubify some Java?
Hello JRuby People,

I'm not quite ready to JRubyify yet but,
I'm working on a mini-project which requires that I screen-capture a
portion of my x-display on a linux box.

It looks like I can use a class in Java named "Robot" to do this:
- http://java.sun.com/javase/6/docs/api/java/awt/Robot.html

I figure any class (even if it is a Java class) named "Robot" deserves
my attention.

So I ran this query:
- http://www.google.com/search?q=java+robot+screencapture

And this page looks good:
- http://www.rgagnon.com/javadetails/java-0489.html

I see this example:

import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;

class ScreenCapture {
public static void main(String args[]) throws
AWTException, IOException {
// capture the whole screen
BufferedImage screencapture = new Robot().createScreenCapture(
new Rectangle(Toolkit.getDefaultToolkit().getScreenSize
()) );

// Save as JPEG
File file = new File("screencapture.jpg");
ImageIO.write(screencapture, "jpg", file);

// Save as PNG
// File file = new File("screencapture.png");
// ImageIO.write(screencapture, "png", file);
}
}

My question:
Is it possible to transform the above Java-syntax into Ruby-syntax
which could be interpreted by JRuby?

Or I could ask it this way:
How do I transform the above Java-syntax into JRuby-syntax?

--Audrey

Dear Audrey,

you can use Java classes in Jruby straight away:

http://blogs.sun.com/coolstuff/entry/using_java_classes_in_jruby

For Linux automation, you might want to look at (the non-Java)
xdotool and its Ruby gem binding xdo:

http://osdir.com/ml/ruby-talk/2009-08/msg01393.html


You might combine that with one of the many ways to take screenshots
in Linux:

http://tips.webdesign10.com/how-to-take-a-screenshot-on-ubuntu-linux

Best regards,

Axel
 
I

Ilan Berci

Your responses were amazingly concise and to the point, I was hoping you
could provide me with some marriage counseling when you have the time :)

ilan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top