Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 1:29 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Wed Sep 26, 2012 4:37 pm 
Offline

Joined: Wed Sep 26, 2012 4:16 pm
Posts: 3
Hello,

I've recently given up on using slick's gui components because there is way to much stuff I have to implement on my own.
So I'll give TWL a try...

My question is: How does event handling (e.g. button clicks) work in TWL?
I can pass a runnable to a button like this:

Code:
        btn.addCallback(new Runnable() {
            public void run() {
                System.out.println("It works!");
            }
        });


Now, is run() executed in the same thread as the slick update method?
Or is it possible, that the button handler and update() run at the same time?
Can I safely write to the same variables from both the handler and update() ?


Top
 Profile  
 
PostPosted: Thu Sep 27, 2012 10:10 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
Runnable is just an interface with a run() method - it has nothing to do with threads.

TWL is not thread safe except very few places - mostly only GUI.invokeLaster and GUI.invokeAsync are thread safe.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Sep 28, 2012 7:40 pm 
Offline

Joined: Wed Sep 26, 2012 4:16 pm
Posts: 3
Okay. So now I understand that a runnable does not necessarily mean that there is a new thread.
But I still don't understand in which thread the eventhandler is executed. Is it the same as for update() ?

Thanks for your help


Top
 Profile  
 
PostPosted: Fri Sep 28, 2012 9:03 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1172
Yes

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Sep 28, 2012 9:57 pm 
Offline

Joined: Wed Sep 26, 2012 4:16 pm
Posts: 3
Thank you!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group