Two threads run always in wrong order, plz help :( (graphics and music)
I have managed to make two threads.
The first thread is supposed to refresh images on screen by JPanel.
The second thread is supposed to play midi music.
In my code the second thread is established onlyafter the first thread has already succesfullyfinished.
However when running the code, I will always hear the midi sequence first as a whole and only after that the images will be updated on screen. This is annoying.I would like to graphics update emerge exactly at the same time as music begins.
Please help me, I am running out of time.
A scetch of my program:
privatestaticclass ThreadAction1implements Runnable{
publicvoid run(){
updateScreenByJPanels();
}
}
privatestaticclass ThreadAction2implements Runnable{
publicvoid run(){
playMidiMusic();
}
}
privatevoid mouseClickedOnImage(){
Thread t1 =new Thread(new ThreadAction());
t1.start();
while (t1.isAlive()){
t1.join(timeIntervalForCheckingIsThreadStillAliveMillis);
if (((System.currentTimeMillis() - startingTimeMillis) > patientWaitingTimeForThreadMillis) && t1.isAlive()){
t1.interrupt();
t1.join();
}
}
Thread t2 =new Thread(new ThreadAction2());
t2.start();
while (t2.isAlive()){
t2.join(timeIntervalForCheckingIsThreadStillAliveMillis);
if (((System.currentTimeMillis() - startingTimeMillis) > patientWaitingTimeForThreadMillis) && t2.isAlive()){
t2.interrupt();
t2.join();
}
}
}

