public class DemoRobot
extends java.awt.Robot
This class is designed to provide an automated demonstration for a graphical application. By reading a script from an XML script file, a sequence of commands can be provided in advance, so anyone can demo a particular application without knowledge of how it works.
The XML file is specified as a command-line argument. Type java
DemoRobot scriptFile.xml
to run the demonstration using
scriptFile.xml. This XML file can contain the following elements:
The following is a sample xml script file:
<demoScript className="prajna.demo.TimeFlowDemo" width="600" height="600"> <enterText text="MD197" /> <moveTo x="280" y="230" steps="10" /> <click button="1" /> <moveTo x="470" y="100" steps="40" /> <click button="1" /> <click button="3" /> <sleep millis="2000" /> <moveTo x="505" y="115" steps="5" /> <click button="1" /> <moveTo x="400" y="30" steps="10" /> <click button="1" count="2" /> <enterText text="MD216" /> <moveTo x="180" y="130" steps="15" /> <showHint hint="Are we there yet?" millis="5000" /> <moveTo x="280" y="230" steps="10" /> </demoScript>
Constructor and Description |
---|
DemoRobot()
Creates a new DemoRobot object.
|
Modifier and Type | Method and Description |
---|---|
void |
click(int button)
Click the appropriate mouse button.
|
void |
click(int button,
int count)
Click the appropriate mouse button.
|
void |
dragTo(int xCoord,
int yCoord)
Click and drag the cursor to the specified location.
|
void |
dragTo(int button,
int xCoord,
int yCoord,
int steps)
Click and drag the cursor to the specified location.
|
void |
enterText(java.lang.String text)
Enters text from the keyboard.
|
javax.swing.JFrame |
getTopFrame() |
boolean |
isPaused() |
void |
loadScript(java.lang.String xmlFile)
Loads a script from an XML file.
|
static void |
main(java.lang.String[] args)
Main method to run the DemoRobot
|
void |
moveTo(int xCoord,
int yCoord,
int steps)
Move to the specified point in the appropriate number of steps.
|
void |
moveTo(java.awt.Point pt,
int steps)
Move to the specified point in the appropriate number of steps
|
void |
playScript()
Plays through the demo script.
|
void |
setPaused(boolean pauseFlag) |
void |
showHint(java.lang.String text,
int millis)
Displays a pop-up message for descriptive text.
|
boolean |
startApp()
Start the application that has been set up.
|
public DemoRobot() throws java.awt.AWTException
java.awt.AWTException
- if the platform configuration does not allow
low-level input control. This exception is always thrown
when GraphicsEnvironment.isHeadless() returns truepublic void click(int button)
button
- the mouse button to clickpublic void click(int button, int count)
count
times.button
- the mouse button to clickcount
- the number of repeat clicks.public void dragTo(int xCoord, int yCoord)
xCoord
- the destination X coordinateyCoord
- the destination Y coordinatepublic void dragTo(int button, int xCoord, int yCoord, int steps)
button
- the mouse button to hold down while draggingxCoord
- the destination X coordinateyCoord
- the destination Y coordinatesteps
- the number of steps to usepublic void enterText(java.lang.String text)
text
- The text string to enterpublic javax.swing.JFrame getTopFrame()
public boolean isPaused()
public void loadScript(java.lang.String xmlFile) throws java.lang.Exception
xmlFile
- the XML file to loadjava.lang.Exception
- Any exception generated from the effort to load the
XML file.public void moveTo(int xCoord, int yCoord, int steps)
xCoord
- the destination X coordinateyCoord
- the destination Y coordinatesteps
- the number of steps to usepublic void moveTo(java.awt.Point pt, int steps)
pt
- the destination pointsteps
- the number of steps to usepublic void playScript()
public void setPaused(boolean pauseFlag)
pauseFlag
- the paused to setpublic void showHint(java.lang.String text, int millis)
text
- the text hint to displaymillis
- how long to display the text (in milliseconds)public boolean startApp()
public static void main(java.lang.String[] args)
args
- a list of string arguments. There should be one argument -
the name of the XML file containing the demo script