Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java, run/wait/run

Name: Anonymous 2008-09-12 23:03

I've written a program in Java that will let you select the number of 'steps' you want it to take (these represent days in the simulation).
Now I made a run option too but I can not get it to work properly.
I want it to run for X steps, after every step it needs to update the views.

This is what I tried:
for (int i = 0;i<100;i++) {
  try {
    model.simulate(1); (simulates 1 step)
    Thread.currentThread().sleep(500);
  } catch (InterruptedException e1) {
    e1.printStackTrace();
 }
}

The problem is that it will not update the views, only after 100 steps have been completed it will update the views.
I update the views using setChanged() & notifyObservers() which works when I manually do 1 step.

Any suggestions?

Name: Anonymous 2008-09-12 23:50

I don't speak The Bloated Language Java, but you should probably make your thread wait on a condition (eg: viewUpdated) instead of sleep(). Or whatever the equivalent is with your observer bullshit.

Otherwise it's pretty much impossible to tell what the problem is since you seem to hide all the shit in model::simulate().

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List