rock
01-13-2003, 09:32 AM
I asked this first over at Sun's Java forums, but the forum is so active questions often get overlooked and drop off the front page too fast. So here it is here - just looking for a point in the right direction:
I have a 1D (i) model evolving in time (k).
The class extends JFrame, and there's nothing else in the GUI, so at this point I don't even need to worry about a user pressing Cancel. The basic class is somthing like:
for (i=0; i<imax; i++) {
... // run across domain
}
updateGraph();
// this is the main loop
for (k=1; k<kmax; k++) {
... //boundary condition
for (i=0; i<imax; i++) {
... // run across domain
}
... //boundary condition
updateGraph();
}
The code runs fine, but the JFrame is not even drawn for the first time until the model ends. I know the solution is to create a separate thread, but where? For the loop or for the updateGraph() method?
I understand well enough the thread examples I have read, but the implementation here escapes me.
My first thought was to "implements Runnable", but it isn't clear what to put in run(). Having run() just call updateGraph() didn't work. If I have a separate thread class (class LoopThread extends Thread) called from the constructor, would that work? Seems I may have a problem getting to some fields then (they'd all have to become public: Yuk).
Can anyone point me in the right direction?
I have a 1D (i) model evolving in time (k).
The class extends JFrame, and there's nothing else in the GUI, so at this point I don't even need to worry about a user pressing Cancel. The basic class is somthing like:
for (i=0; i<imax; i++) {
... // run across domain
}
updateGraph();
// this is the main loop
for (k=1; k<kmax; k++) {
... //boundary condition
for (i=0; i<imax; i++) {
... // run across domain
}
... //boundary condition
updateGraph();
}
The code runs fine, but the JFrame is not even drawn for the first time until the model ends. I know the solution is to create a separate thread, but where? For the loop or for the updateGraph() method?
I understand well enough the thread examples I have read, but the implementation here escapes me.
My first thought was to "implements Runnable", but it isn't clear what to put in run(). Having run() just call updateGraph() didn't work. If I have a separate thread class (class LoopThread extends Thread) called from the constructor, would that work? Seems I may have a problem getting to some fields then (they'd all have to become public: Yuk).
Can anyone point me in the right direction?