< prev index next >

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

Print this page




 625      * Sets the number of milliseconds this Robot sleeps after generating an event.
 626      *
 627      * @param  ms the delay duration in milliseconds
 628      * @throws IllegalArgumentException If {@code ms}
 629      *         is not between 0 and 60,000 milliseconds inclusive
 630      */
 631     public synchronized void setAutoDelay(int ms) {
 632         checkDelayArgument(ms);
 633         autoDelay = ms;
 634     }
 635 
 636     /*
 637      * Automatically sleeps for the specified interval after event generated.
 638      */
 639     private void autoDelay() {
 640         delay(autoDelay);
 641     }
 642 
 643     /**
 644      * Sleeps for the specified time.
 645      * To catch any {@code InterruptedException}s that occur,
 646      * {@code Thread.sleep()} may be used instead.

 647      *
 648      * @param  ms time to sleep in milliseconds
 649      * @throws IllegalArgumentException if {@code ms}
 650      *         is not between 0 and 60,000 milliseconds inclusive
 651      * @see java.lang.Thread#sleep
 652      */
 653     public synchronized void delay(int ms) {
 654         checkDelayArgument(ms);
 655         try {
 656             Thread.sleep(ms);
 657         } catch(InterruptedException ite) {
 658             ite.printStackTrace();
 659         }
 660     }
 661 
 662     private void checkDelayArgument(int ms) {
 663         if (ms < 0 || ms > MAX_DELAY) {
 664             throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
 665         }
 666     }
 667 
 668     /**
 669      * Waits until all events currently on the event queue have been processed.
 670      * @throws  IllegalThreadStateException if called on the AWT event dispatching thread
 671      */
 672     public synchronized void waitForIdle() {
 673         checkNotDispatchThread();
 674         SunToolkit.flushPendingEvents();
 675         ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
 676     }
 677 
 678     private void checkNotDispatchThread() {


 625      * Sets the number of milliseconds this Robot sleeps after generating an event.
 626      *
 627      * @param  ms the delay duration in milliseconds
 628      * @throws IllegalArgumentException If {@code ms}
 629      *         is not between 0 and 60,000 milliseconds inclusive
 630      */
 631     public synchronized void setAutoDelay(int ms) {
 632         checkDelayArgument(ms);
 633         autoDelay = ms;
 634     }
 635 
 636     /*
 637      * Automatically sleeps for the specified interval after event generated.
 638      */
 639     private void autoDelay() {
 640         delay(autoDelay);
 641     }
 642 
 643     /**
 644      * Sleeps for the specified time.
 645      * <p>
 646      * If the invoking thread is interrupted while waiting, then its interrupt
 647      * status will be set and this method returns immediately.
 648      *
 649      * @param  ms time to sleep in milliseconds
 650      * @throws IllegalArgumentException if {@code ms} is not between {@code 0}
 651      *         and {@code 60,000} milliseconds inclusive

 652      */
 653     public void delay(int ms) {
 654         checkDelayArgument(ms);
 655         try {
 656             Thread.sleep(ms);
 657         } catch(final InterruptedException ignored) {
 658             Thread.currentThread().interrupt(); // Preserve interrupt status
 659         }
 660     }
 661 
 662     private void checkDelayArgument(int ms) {
 663         if (ms < 0 || ms > MAX_DELAY) {
 664             throw new IllegalArgumentException("Delay must be to 0 to 60,000ms");
 665         }
 666     }
 667 
 668     /**
 669      * Waits until all events currently on the event queue have been processed.
 670      * @throws  IllegalThreadStateException if called on the AWT event dispatching thread
 671      */
 672     public synchronized void waitForIdle() {
 673         checkNotDispatchThread();
 674         SunToolkit.flushPendingEvents();
 675         ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
 676     }
 677 
 678     private void checkNotDispatchThread() {
< prev index next >