je suis en train de coder un jeu pour mobile donc sous j2me ou plusieurs thread sont execute en meme temps. seulement a un certain moment un condition est execute mais cela n'est pas refleté sur la gui. probleme d'interblocage? pas sur?
j'ai besoin d'aide car je suis a cours d'idee. voila le code:
class Class1 extends Sprite implements Runnable {
int counter = 0;
Thread t;
boolean b = false;
public Class1(Image image, int frameWidth, int frameHeight) {
super(image, frameWidth, frameHeight);
t = new Thread(this);
}
public void startJumping() {
b = true;
t.start();
}
public synchronized void stopJumping() {
b = false;
this.setFrame(0);
setCounter(0);
try{
this.wait();
}catch(InterruptedException ex){
ex.printStackTrace();
}
}
public synchronized void restartJumping(){
b = true;
this.notify();
}
public void run() {
while(b){
counter++;
try{
Thread.sleep(50);
}catch(Exception ex){
ex.printStackTrace();
}
if(counter == 12){
stopJumping();
}
}
}
}
Partager