0

I have been trying to delay a simple piece of code in Java for a while, unfortunately if use a thread then the following code will not work as it is apart of the thread and i get lots of exceptions.

I am trying to delay another way like this:

    try {
        Robot robot = new Robot();
        robot.delay(5000);

                    //My code here..
    } catch (AWTException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

The problem is, is that it freezes my hole application just like Thread.sleep(ms) would do if you slept the main thread of the application.

I was wondering if there is any way around it freezing my hole application.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user2826304
  • 97
  • 1
  • 2
  • 10
  • Why are you using the Robot class? The primary purpose of Robot is to facilitate automated testing of Java platform implementations. – DaveJohnston Feb 08 '14 at 13:27
  • Can you suggest any other possible way of delaying without it freezing my application please? – user2826304 Feb 08 '14 at 13:29
  • You cannot put a sleep in the AWT thread without it freezing the UI. You will need to explain further why you cannot put your code in a new thread. – DaveJohnston Feb 08 '14 at 13:31

0 Answers0