How does the Robot actually control a program? You first start the program you want to control, then start the Robot. After you click the Go button, the Robot disappears, which gives the focus back to the program you want to control. From then on, the Robot can send it keystrokes or control it with the mouse.
When the Robot is done with the tasks you've given it, it reappears. For example, take a look at Figure 7.2, where the Robot has entered the text “Hello from the robot.” in Windows WordPad. Cool.
NOTE
Note the steps used to run the Robot. First, you start the program you want to control. Then you start the Robot.
After entering the commands you want to execute, or the name of the file that holds the commands, you click the Go button. The Robot will disappear, and the focus will revert to the program you want to control. After the Robot is done running that program, it'll reappear.
How does the Robot do what it does? It uses a Java class called, not surprisingly, the Java Robot class. This class first appeared in Java 1.3 and has been getting better ever since.
Sun's purpose in creating this class was to “facilitate automated testing of Java platform implementations,” but that's boring. It's much better to use this class to generate low-level user-interface events and control other programs by remote control, as the Robot project does.
18.224.62.25