tags:

views:

135

answers:

2

Hi there,

I need to run an external application from within my Java code. I can run the application with Runtime r = Runtime.getRuntime() and then r.exec(...), however, this brings up the GUI of the application. And I still need enter some settings in some fields and press enter. So:

Is there some way to handle a GUI (filling out fields, pressing "return"..etc) from within Java code?

Thanks in advance for any answers,

Anas

+3  A: 

Use the AWT Robot class:

"This class is used to generate native system input events for the purposes of test automation, self-running demos, and other applications where control of the mouse and keyboard is needed."

RichieHindle
Are you sure that java.awt.Robot can access the other applications as well?
Vanya
Ok, thank you for info on this class. I will try this the next chance I get and report the results. I am on widown Vista, and I found that I can simplify the handling the GUI (by changing the default settings to side-step filling out any field), but I would still need to press "enter". I think this might do, we'll see
The Robot class is designed to emulate mouse clicks, so it definitely can access other systems - it is doing hardware mouse clicks sent to the underlying OS.
aperkins
A: 

Hi,

Thanks RichieHindle and Vanya for your comments. AWT Robot class does work with an external softwatre (in this instance, I only need to press an enter. It did that, no problem). But further handling seems quite difficult, since every key stroke (entering a username) needs a java line (unless there is someshort cut that I missed). I will try to automata the process more, or find some work around.

Thank you, this was informative.

Anas

You may want to use something built on top of the java.awt.Robot class - like Abbot and Costello - http://abbot.sourceforge.net/doc/overview.shtml
Nate