Java Doc for Robot.java in  » 6.0-JDK-Core » AWT » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » AWT » java.awt 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.awt.Robot

Robot
public class Robot (Code)
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. The primary purpose of Robot is to facilitate automated testing of Java platform implementations.

Using the class to generate input events differs from posting events to the AWT event queue or AWT components in that the events are generated in the platform's native input queue. For example, Robot.mouseMove will actually move the mouse cursor instead of just generating mouse move events.

Note that some platforms require special privileges or extensions to access low-level input control. If the current platform configuration does not allow input control, an AWTException will be thrown when trying to construct Robot objects. For example, X-Window systems will throw the exception if the XTEST 2.2 standard extension is not supported (or not enabled) by the X server.

Applications that use Robot for purposes other than self-testing should handle these error conditions gracefully.
version:
   1.37, 05/05/07
author:
   Robi Khan
since:
   1.3


Inner Class :static class RobotDisposer implements sun.java2d.DisposerRecord


Constructor Summary
public  Robot()
     Constructs a Robot object in the coordinate system of the primary screen.


throws:
  AWTException - if the platform configuration does not allowlow-level input control.

public  Robot(GraphicsDevice screen)
     Creates a Robot for the given screen device.

Method Summary
public synchronized  BufferedImagecreateScreenCapture(Rectangle screenRect)
     Creates an image containing pixels read from the screen.
public synchronized  voiddelay(int ms)
     Sleeps for the specified time.
public synchronized  intgetAutoDelay()
     Returns the number of milliseconds this Robot sleeps after generating an event.
public synchronized  ColorgetPixelColor(int x, int y)
     Returns the color of a pixel at the given screen coordinates.
public synchronized  booleanisAutoWaitForIdle()
     Returns whether this Robot automatically invokes waitForIdle after generating an event.
public synchronized  voidkeyPress(int keycode)
     Presses a given key.
public synchronized  voidkeyRelease(int keycode)
     Releases a given key.

Key codes that have more than one physical key associated with them (e.g.

public synchronized  voidmouseMove(int x, int y)
     Moves mouse pointer to given screen coordinates.
public synchronized  voidmousePress(int buttons)
     Presses one or more mouse buttons.
public synchronized  voidmouseRelease(int buttons)
     Releases one or more mouse buttons.
public synchronized  voidmouseWheel(int wheelAmt)
     Rotates the scroll wheel on wheel-equipped mice.
public synchronized  voidsetAutoDelay(int ms)
     Sets the number of milliseconds this Robot sleeps after generating an event.
public synchronized  voidsetAutoWaitForIdle(boolean isOn)
     Sets whether this Robot automatically invokes waitForIdle after generating an event.
public synchronized  StringtoString()
     Returns a string representation of this Robot.
public synchronized  voidwaitForIdle()
     Waits until all events currently on the event queue have been processed.


Constructor Detail
Robot
public Robot() throws AWTException(Code)
Constructs a Robot object in the coordinate system of the primary screen.


throws:
  AWTException - if the platform configuration does not allowlow-level input control. This exception is always thrown whenGraphicsEnvironment.isHeadless() returns true
throws:
  SecurityException - if createRobot permission is not granted
See Also:   java.awt.GraphicsEnvironment.isHeadless
See Also:   SecurityManager.checkPermission
See Also:   AWTPermission




Robot
public Robot(GraphicsDevice screen) throws AWTException(Code)
Creates a Robot for the given screen device. Coordinates passed to Robot method calls like mouseMove and createScreenCapture will be interpreted as being in the same coordinate system as the specified screen. Note that depending on the platform configuration, multiple screens may either:
  • share the same coordinate system to form a combined virtual screen
  • use different coordinate systems to act as independent screens
This constructor is meant for the latter case.

If screen devices are reconfigured such that the coordinate system is affected, the behavior of existing Robot objects is undefined.
Parameters:
  screen - A screen GraphicsDevice indicating the coordinatesystem the Robot will operate in.
throws:
  AWTException - if the platform configuration does not allowlow-level input control. This exception is always thrown whenGraphicsEnvironment.isHeadless() returns true.
throws:
  IllegalArgumentException - if screen is not a screenGraphicsDevice.
throws:
  SecurityException - if createRobot permission is not granted
See Also:   java.awt.GraphicsEnvironment.isHeadless
See Also:   GraphicsDevice
See Also:   SecurityManager.checkPermission
See Also:   AWTPermission





Method Detail
createScreenCapture
public synchronized BufferedImage createScreenCapture(Rectangle screenRect)(Code)
Creates an image containing pixels read from the screen. This image does not include the mouse cursor.
Parameters:
  screenRect - Rect to capture in screen coordinates The captured image
throws:
  IllegalArgumentException - if screenRect width and height are not greater than zero
throws:
  SecurityException - if readDisplayPixels permission is not granted
See Also:   SecurityManager.checkPermission
See Also:   AWTPermission



delay
public synchronized void delay(int ms)(Code)
Sleeps for the specified time. To catch any InterruptedExceptions that occur, Thread.sleep() may be used instead.
Parameters:
  ms - time to sleep in milliseconds
throws:
  IllegalArgumentException - if ms is not between 0 and 60,000 milliseconds inclusive
See Also:   java.lang.Thread.sleep



getAutoDelay
public synchronized int getAutoDelay()(Code)
Returns the number of milliseconds this Robot sleeps after generating an event.



getPixelColor
public synchronized Color getPixelColor(int x, int y)(Code)
Returns the color of a pixel at the given screen coordinates.
Parameters:
  x - X position of pixel
Parameters:
  y - Y position of pixel Color of the pixel



isAutoWaitForIdle
public synchronized boolean isAutoWaitForIdle()(Code)
Returns whether this Robot automatically invokes waitForIdle after generating an event. Whether waitForIdle is automatically called



keyPress
public synchronized void keyPress(int keycode)(Code)
Presses a given key. The key should be released using the keyRelease method.

Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.
Parameters:
  keycode - Key to press (e.g. KeyEvent.VK_A)
throws:
  IllegalArgumentException - if keycode is nota valid key
See Also:   Robot.keyRelease(int)
See Also:   java.awt.event.KeyEvent




keyRelease
public synchronized void keyRelease(int keycode)(Code)
Releases a given key.

Key codes that have more than one physical key associated with them (e.g. KeyEvent.VK_SHIFT could mean either the left or right shift key) will map to the left key.
Parameters:
  keycode - Key to release (e.g. KeyEvent.VK_A)
throws:
  IllegalArgumentException - if keycode is not avalid key
See Also:   Robot.keyPress(int)
See Also:   java.awt.event.KeyEvent




mouseMove
public synchronized void mouseMove(int x, int y)(Code)
Moves mouse pointer to given screen coordinates.
Parameters:
  x - X position
Parameters:
  y - Y position



mousePress
public synchronized void mousePress(int buttons)(Code)
Presses one or more mouse buttons. The mouse buttons should be released using the mouseRelease method.
Parameters:
  buttons - the Button mask; a combination of one or moreof these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK

throws:
  IllegalArgumentException - if the button mask is not avalid combination
See Also:   Robot.mouseRelease(int)



mouseRelease
public synchronized void mouseRelease(int buttons)(Code)
Releases one or more mouse buttons.
Parameters:
  buttons - the Button mask; a combination of one or moreof these flags:
  • InputEvent.BUTTON1_MASK
  • InputEvent.BUTTON2_MASK
  • InputEvent.BUTTON3_MASK

See Also:   Robot.mousePress(int)
throws:
  IllegalArgumentException - if the button mask is not a validcombination



mouseWheel
public synchronized void mouseWheel(int wheelAmt)(Code)
Rotates the scroll wheel on wheel-equipped mice.
Parameters:
  wheelAmt - number of "notches" to move the mouse wheelNegative values indicate movement up/away from the user,positive values indicate movement down/towards the user.
since:
   1.4



setAutoDelay
public synchronized void setAutoDelay(int ms)(Code)
Sets the number of milliseconds this Robot sleeps after generating an event.
throws:
  IllegalArgumentException - If ms is not between 0 and 60,000 milliseconds inclusive



setAutoWaitForIdle
public synchronized void setAutoWaitForIdle(boolean isOn)(Code)
Sets whether this Robot automatically invokes waitForIdle after generating an event.
Parameters:
  isOn - Whether waitForIdle is automatically invoked



toString
public synchronized String toString()(Code)
Returns a string representation of this Robot. the string representation.



waitForIdle
public synchronized void waitForIdle()(Code)
Waits until all events currently on the event queue have been processed.
throws:
  IllegalThreadStateException - if called on the AWT event dispatching thread



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.