We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Event dispatching, listening and the draw function
Page Index Toggle Pages: 1
Event dispatching, listening and the draw function (Read 549 times)
Event dispatching, listening and the draw function
Dec 2nd, 2007, 7:28pm
 
Hi,
is there a way in processing to dispatch events inside an object and having other objects listening to it. I've found the broadcaster library, but unfortunately it is not documented. Does anyone know how this library works, or how to realise event communication in processing?

And another beginner question... sorry i'm new to processing. I don't really understand the frame/loop draw() concept. If I create an object in the setup, is there a way that it runs its own timed loop. Let's say I have an object that is changing some values every 50 milliseconds, but the framerate of the applet is 10 fps. Could I broadcast something like an update event in the draw() function and having my object listening to it, so that it redraws itself with the values it has at this time?

Maybe a weird concept, does it make sense at all?

many thanks
Re: Event dispatching, listening and the draw func
Reply #1 - Dec 3rd, 2007, 8:04am
 
You can do something like

[code]

class TimedClass extends Thread{
 float delay;
 TimedClass( float d ){
   delay = d;
   start();
 }

 void run(){
   while(true){
     commands();
     try{
       sleep(delay);
     } catch(Exception e){}
   }
 }

 void commands(){
   // your stuff here
 }
Re: Event dispatching, listening and the draw func
Reply #2 - Dec 3rd, 2007, 7:32pm
 
Thanks soo much!
It works. Just had to change "float delay" into "long delay" because sleep() seems to need a long as argument.

Where can i find a documentation of classes like "Thread" that can be extended within a sketch? Which classes or libraries of the Java language can actually be used within a sketch?

Maybe there is an easy way to realise some sort of event communication between objects, with a broadcaster class or so. So all objects get that broadcast object while construction and look/listen to it every frame/loop. But then every object has to be a thread?!... Would that be CPU hungry?

Thanks a lot for any input/ideas and especially help!
Page Index Toggle Pages: 1