the main problem is that I don't know how long my method will take to finish, I have 2 threads, one to execute the method that do stuff and the other one excute the progress of the progress bar, this is my first thread:
@Override
public void run() {
//This is a static variable, indicate when the method analyzeSentence finish
finish = false;
String sentence = analyzeSentence();
try {
Thread.sleep( 1000 );
} catch (InterruptedException e){
System.err.println( e.getMessage() );
}
finish = true;
}
And in my second thread (the progress bar thread) I have this:
@Override
public void run() {
i = 1;
while(!Analyze.finish) {
i = (i > 100) ? 1 : i+1; //Here I have the problem
progressBar.setValue(i);
progressBar.repaint();
try {
Thread.sleep(this.value);
} catch (InterruptedException e) {
System.err.println(e.getMessage());
}
if(Analyze.finish) {
progressBar.setValue(100);
break;
}
}
}
The problem is that the progress bar reset their values to zero but the method still not over so the progress bar is filled again and again... Is there any way to obtain the lenght of the time that the method takes to finish?