Hi guys, I'm not really sure how to ask this or what to even search for. I want to write a Java program that can feed data into another program. If the other program had command line parameters then I'd know what to do, but suppose the program I want to provide input to is a GUI application whose source code is not available to me.

To explain a bit better, I have a GUI form with Name amongst other input fields and this program is totally independent from the program I'm writing. Is it possible for me to populate these input fields using a Java program? If so, can someone please point me to the correct package/classes? Sample code would be great!

Thanks in advance :icon_smile:

I assume that the other program (GUI) has a list of classes. Do you know the elements of those classes as well as their methods. If the main GUI page has a constructor you call it with the appropriate data that you get from your program.
If the elements of the GUI are public you can 'set' their values, after you have called the constructor of the program in your main:

In general how you set values:

JTextField field = new JTextField();
field.setText("New Text");

In your main:

OtherProgramGUI gui = new OtherProgramGUI();
gui.field.setText("New Text");

gui.setVisible(true);

If all of the elements and the methods are private then you have a problem

commented: Thank you for the awesome suggestion :) +3

If you don't have an API that you can use for the target program then about the only thing you could try would be the Robot class. There's a tutorial that demonstrates how it can be used to interact with other programs here: http://www.developer.com/java/other/article.php/2212401

It would be a clunky solution at best, but if you have no API nor command line access, it's about the only thing left. Unless, of course, you can hack the underlying data store and write in the field values directly ;)

commented: You're just bloody brilliant mate! Thanks for the reply :) +3

...If all of the elements and the methods are private then you have a problem

The program I'm trying to automate input to isn't a Java program but your solution does sound interesting. Suppose that it was the case that the required resources are declared private, would it even be possible to get access to it (if of course only the class files are available)? I know that there are reserve engineering tools available (that would break the terms and conditions of some programs) but without messing or hacking the code, it really isn't possible hey?

Thank you for directing me to the Robot class Ezzaral!! It's just what I was looking for :icon_smile: And you even provide me with a very useful tutorial! You so rock :icon_cool:
I'm not really good at hacking so this is the most appropriate solution for me hehe

Kind regards,
Pooven

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.