O'Reilly logo

Java™ After Hours: 10 Projects You'll Never Do at Work by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Executing Commands

Having read all the commands to execute, you can loop over those commands with a for loop. Each command, such as t:abc, which sends the text “abc” to the program the Robot project is controlling, is made up of an operation (“t” for text here) and data (“abc” here).

Here's how the Robot project extracts the operation and data from each command as it loops over all commands:

public void actionPerformed(ActionEvent e) 
{
    try{
        .
        .
        .
        for (int loopIndex = 0; loopIndex < numberCommands;
					loopIndex++){
					String operation = commands[loopIndex].substring(0, 1);
					String data = commands[loopIndex].substring(2);

        .
        .
        .

Sending Keystrokes

Each command is a single character, so you can use a switch statement to handle them all. Each operation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required