title: Javafx and Sun.glass robot causing problems IllegalStateException due to use of Threads
body: <p>I am writing a JavaFX controller which moves the mouse once in every 5 seconds. This controller also does some other work concurrently while doing this. Hence I used separate threads for each of these tasks. Below is my code:</p>
  
  <pre><code>Thread dynamicMouseThread = new Thread(new Runnable() {
      @Override
      public void run() {
          boolean isRunning = true;
          long timeout = 5000;
          int x = 5;
          Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot();
          while (isRunning) {
              try {
                  Thread.sleep(timeout);
              } catch (InterruptedException ex) {
                  isRunning = false;
              }
              x = x == 5 ? x + 5 : 5;
              robot.mouseMove(x, 5);  // This line causes the error.
          }
      }
  });
  
  
  @Override
  public void initialize(URL url, ResourceBundle rb) {
      dynamicTimerThread.setName("Dynamic Timer Thread");
      dynamicMouseThread.setName("Dynamic Mouse Thread");
      dynamicTimerThread.start();
      dynamicMouseThread.start();
  }
  </code></pre>
  
  <p>This is the error I seem to be getting. Please help me out. what am I doing wrong?</p>
  
  <pre><code>Exception in thread "Dynamic Mouse Thread" java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = Dynamic Mouse Thread
  at com.sun.glass.ui.Application.checkEventThread(Application.java:427)
  at com.sun.glass.ui.Robot.&lt;init&gt;(Robot.java:52)
  at com.sun.glass.ui.win.WinRobot.&lt;init&gt;(WinRobot.java:33)
  at com.sun.glass.ui.win.WinApplication.createRobot(WinApplication.java:205)
  at main.SubDocumentController$1.run(SubDocumentController.java:56)
  at java.lang.Thread.run(Thread.java:745)
  </code></pre>