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 & HelpPrograms › Threads, how
Page Index Toggle Pages: 1
Threads, how? (Read 1090 times)
Threads, how?
Dec 11th, 2005, 12:26pm
 
Hi

Ive written a wallpaper maker, but the problem is
while its calculating the pattern its gui isnt working.
at least i would like to put a message or a progress bar which shows its working.
In java i solve it with threads but in processing i dont know how.

thanks
bye
Viktor

u can find the wallpaper maker applet here:
http://people.inf.elte.hu/kelemen/symmetry/applet/
Re: Threads, how?
Reply #1 - Dec 13th, 2005, 5:27pm
 
you can create threads in processing the same as you would in java. the inside of draw() you can just check to see if the thread is done, and if it is, draw something based on what it has figured out (or draw a progress bar type of thing as it's working).
Re: Threads, how?
Reply #2 - Dec 29th, 2005, 3:19am
 
i searched around a while for a thread example in proce55ing but couldn't find it, so here's an example i made based on sun's examples.



Code:

// this is the class that will run our thread
public class MyThread extends Thread {
int ctr;
public MyThread(String str) {
super(str); // we give it a name.
ctr = 0;
}

// run() is like the thread's main() or draw()
public void run() {
while(true) {
background(int(random(255)));
println("run: " + getName() + " " + ctr);
ctr++;
try {
sleep((long)(1000)); // 1 sec delay
} catch (InterruptedException e) {}
}

}
}

void setup() {

size(640,480);

new MyThread("Test").start(); // create and start the thread!
}

void draw() {
rectMode(CENTER);
noStroke();
fill(0,0,0,15);

rect(mouseX, mouseY, 50, 50);
}
Page Index Toggle Pages: 1