How to handle a GUI of an external software from within Java code

橙三吉。 提交于 2020-01-25 00:06:05

问题


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


回答1:


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."




回答2:


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



来源:https://stackoverflow.com/questions/1347988/how-to-handle-a-gui-of-an-external-software-from-within-java-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!