< prev index next >

src/java.desktop/share/classes/java/awt/Robot.java

Print this page




 360 
 361     /**
 362      * Releases a given key.
 363      * <p>
 364      * Key codes that have more than one physical key associated with them
 365      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 366      * left or right shift key) will map to the left key.
 367      *
 368      * @param   keycode Key to release (e.g. {@code KeyEvent.VK_A})
 369      * @throws  IllegalArgumentException if {@code keycode} is not a
 370      *          valid key
 371      * @see  #keyPress(int)
 372      * @see     java.awt.event.KeyEvent
 373      */
 374     public synchronized void keyRelease(int keycode) {
 375         checkKeycodeArgument(keycode);
 376         peer.keyRelease(keycode);
 377         afterEvent();
 378     }
 379 

































 380     private void checkKeycodeArgument(int keycode) {
 381         // rather than build a big table or switch statement here, we'll
 382         // just check that the key isn't VK_UNDEFINED and assume that the
 383         // peer implementations will throw an exception for other bogus
 384         // values e.g. -1, 999999
 385         if (keycode == KeyEvent.VK_UNDEFINED) {
 386             throw new IllegalArgumentException("Invalid key code");
 387         }
 388     }
 389 
 390     /**
 391      * Returns the color of a pixel at the given screen coordinates.
 392      * @param   x       X position of pixel
 393      * @param   y       Y position of pixel
 394      * @return  Color of the pixel
 395      */
 396     public synchronized Color getPixelColor(int x, int y) {
 397         AffineTransform tx = GraphicsEnvironment.
 398                 getLocalGraphicsEnvironment().getDefaultScreenDevice().
 399                 getDefaultConfiguration().getDefaultTransform();




 360 
 361     /**
 362      * Releases a given key.
 363      * <p>
 364      * Key codes that have more than one physical key associated with them
 365      * (e.g. {@code KeyEvent.VK_SHIFT} could mean either the
 366      * left or right shift key) will map to the left key.
 367      *
 368      * @param   keycode Key to release (e.g. {@code KeyEvent.VK_A})
 369      * @throws  IllegalArgumentException if {@code keycode} is not a
 370      *          valid key
 371      * @see  #keyPress(int)
 372      * @see     java.awt.event.KeyEvent
 373      */
 374     public synchronized void keyRelease(int keycode) {
 375         checkKeycodeArgument(keycode);
 376         peer.keyRelease(keycode);
 377         afterEvent();
 378     }
 379 
 380     /**
 381      * Presses a given unicode key.  The key should be released using the
 382      * {@code keyReleaseUnicode} method.
 383      * <p>
 384      *
 385      * @param   key unicode to press
 386      * @throws  IllegalArgumentException if {@code key} is not
 387      *          a valid unicode key
 388      * @see     #keyReleaseUnicode(int)
 389      * @see     java.awt.event.KeyEvent
 390      */
 391     public synchronized void keyPressUnicode(int key) {
 392         checkKeycodeArgument(key);
 393         peer.keyPressUnicode(key);
 394         afterEvent();
 395     }
 396 
 397     /**
 398      * Releases a given unicode key.
 399      * <p>
 400      *
 401      * @param   key unicode to release
 402      * @throws  IllegalArgumentException if {@code key} is not a
 403      *          valid key
 404      * @see     #keyPressUnicode(int)
 405      * @see     java.awt.event.KeyEvent
 406      */
 407     public synchronized void keyReleaseUnicode(int key) {
 408         checkKeycodeArgument(key);
 409         peer.keyReleaseUnicode(key);
 410         afterEvent();
 411     }
 412 
 413     private void checkKeycodeArgument(int keycode) {
 414         // rather than build a big table or switch statement here, we'll
 415         // just check that the key isn't VK_UNDEFINED and assume that the
 416         // peer implementations will throw an exception for other bogus
 417         // values e.g. -1, 999999
 418         if (keycode == KeyEvent.VK_UNDEFINED) {
 419             throw new IllegalArgumentException("Invalid key code");
 420         }
 421     }
 422 
 423     /**
 424      * Returns the color of a pixel at the given screen coordinates.
 425      * @param   x       X position of pixel
 426      * @param   y       Y position of pixel
 427      * @return  Color of the pixel
 428      */
 429     public synchronized Color getPixelColor(int x, int y) {
 430         AffineTransform tx = GraphicsEnvironment.
 431                 getLocalGraphicsEnvironment().getDefaultScreenDevice().
 432                 getDefaultConfiguration().getDefaultTransform();


< prev index next >