Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  Robot mouseMove helppp (IllegalThreadStateException)  (Read 772 times)
0 Members and 2 Guests are viewing this topic.
Offline kidluff

JGO n00b
*

Posts: 25



« on: 2006-01-20 05:35:38 »

When I set my Robot to "setAutoWaitForIdle(true)" (so it cues the next event after the Robot stops), I get an "IllegalThreadStateException"..

What's wrong  Huh


   Robot mouseBot;
   boolean RobotMove=true;
   
   public void startMouseRobot(){
      try{mouseBot=new Robot();}
      catch(Exception e){}
      mouseBot.setAutoWaitForIdle(true);
      }

   public void robotResetMouse(){
      //set RobotMove to true
      //move cursor
      //set RobotMove to false
      RobotMove=true;
      mouseBot.mouseMove(screenSize.width/2, screenSize.height/2);
      RobotMove=false;
      }


(Im using the boolean RobotMove to determine the difference between a user mouse move and a robot mouse move. Is there another way to do this?)
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #1 on: 2006-01-20 08:35:23 »

You can't wait for idle from the EDT. Because it waits for the EDT to idle.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline kidluff

JGO n00b
*

Posts: 25



« Reply #2 on: 2006-01-20 09:50:51 »

You can't wait for idle from the EDT. Because it waits for the EDT to idle.

I dont get it  Cry
Games published by our own members! Go get 'em!
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #3 on: 2006-01-20 11:21:58 »

If you call the Robot.mouseMove from the EDT (EventDispatcherThread), when setAutoWaitForIdle is true, it will call Robot.waitForIdle() automaticly.

Robot.waitForIdle() may not be called from the EDT, as it waits for the very same EDT to finish. (It cannot wait for itself to finish).

The sun-engineers prevented that that call would be hanging for ever, instead they throw an Exception to warn you.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Offline kidluff

JGO n00b
*

Posts: 25



« Reply #4 on: 2006-01-20 13:15:39 »

Then how can I queue the next action following Robot.mouseMove()? Like after the mouseMove thread is finished?
Offline Riven
« League of Dukes »

JGO Kernel
*****

Posts: 5871
Medals: 255


Hand over your head.


« Reply #5 on: 2006-01-20 13:47:41 »

Just run all calls to Robot from your own thread, or create one, especially for it.

Or disable waitForIdle and roll your own code to handle the situation correctly.

Hi, appreciate more people! Σ ♥ = ¾

Learn how to award medals... and work your way up the social rankings
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.085 seconds with 19 queries.