04-01-2009 08:35 PM
I have a PlayerListener that's supposed to call invalidate on a Field while the Player is playing. I don't know why but the field is not being repainted. Here's the code:
public class PlayerHandler implements PlayerListener { public PlayerHandler() { } public void playerUpdate(Player player, String event, Object data) { if (event == (PlayerListener.STARTED)) { new Thread(new SelectFieldUpdate()).start(); } else if (event == (PlayerListener.STOPPED)) { field.invalidate(); } } private class SelectFieldUpdate implements Runnable { public void run() { while(player.getState() == Player.STARTED) { field.invalidate(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } } } }
of course, i add this listener to my player. any help will be appreciated.
Thanks!
04-02-2009 12:50 AM
04-02-2009 01:55 AM - last edited on 04-02-2009 02:04 AM
yeah I tried the debugger. invalidate is definitely being called. i'm not sure if anything is actually happening though. it looks like paint may have ran once and that's it, but invalidate keeps being called, presumably because of the while loop, so that much is correct. I don't really have a good grasp of the UI Stack and such. is there something that could be interfering with the painting? needless to say the Player is running at the moment, although that should be running in a different thread as well. i tried encapsulating the insides of paint() in a Runnable, but instead nothing got drawn. no clue what's going on....
edit: instead of invalidate() i tried to call setText() on a different LabelField within that Runnable and I got a IllegalStateException
what the heck does this mean?
04-02-2009 10:16 AM
04-02-2009 10:18 AM - last edited on 04-02-2009 10:19 AM
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
//set Text
}
});