# Java, Ruby, JRuby, JRubify some Java?

**URL:** <https://www.ruby-forum.com/t/java-ruby-jruby-jrubify-some-java/175977>\
**Category:** Ruby\
**Created:** [September 23, 2009, 9:01am UTC](https://www.ruby-forum.com/t/java-ruby-jruby-jrubify-some-java/175977 "2009-09-23T09:01:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Audrey\_A\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f475e1/32.png) [@Audrey\_A\_Lee](https://www.ruby-forum.com/u/Audrey_A_Lee)\
**Post date:** [September 23, 2009, 9:01am UTC](https://www.ruby-forum.com/t/java-ruby-jruby-jrubify-some-java/175977/1 "2009-09-23T09:01:11Z")

</div>

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:

- [Robot (Java Platform SE 6)](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:

- [java robot screencapture - Google Search](http://www.google.com/search?q=java+robot+screencapture)

And this page looks good:

- [Get a screen capture and save it as a JPEG - Real's Java How-to](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](http://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

---

<div class="post-metadata">

**Author:** ![Audrey\_A\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f475e1/32.png) [@Audrey\_A\_Lee](https://www.ruby-forum.com/u/Audrey_A_Lee)\
**Post date:** [September 23, 2009, 10:32am UTC](https://www.ruby-forum.com/t/java-ruby-jruby-jrubify-some-java/175977/2 "2009-09-23T10:32:30Z")

</div>

-------- Original-Nachricht --------

> Datum: Wed, 23 Sep 2009 15:25:11 +0900  
> Von: Audrey A Lee [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> An: removed\_email\_address@domain.invalid  
> Betreff: Java, Ruby, JRuby, JRubify some Java?

> my attention.  
> import java.awt.Robot;  
> BufferedImage screencapture = new Robot().createScreenCapture(  
> }

Dear Audrey,

you can use Java classes in Jruby straight away:

[http://blogs.sun.com/coolstuff/entry/using\_java\_classes\_in\_jruby](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:

> **[OSDIR](https://osdir.com)**
>
> edit post Gaming How To Check If US iGaming Platform is Safe July 13, 2021 edit post Gaming What made

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](http://tips.webdesign10.com/how-to-take-a-screenshot-on-ubuntu-linux)

Best regards,

Axel

---

<div class="post-metadata">

**Author:** ![Audrey\_A\_Lee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f475e1/32.png) [@Audrey\_A\_Lee](https://www.ruby-forum.com/u/Audrey_A_Lee)\
**Post date:** [September 23, 2009, 3:13pm UTC](https://www.ruby-forum.com/t/java-ruby-jruby-jrubify-some-java/175977/3 "2009-09-23T15:13:24Z")

</div>

Axel E. wrote:

> 

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
