1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.GameCanvas;
public class Exemple extends GameCanvas implements Runnable {
private Graphics graphics;
private Exemple exemple;
private volatile Thread thread;
public Exemple(){
super( true );
graphics = getGraphics();
graphics.setColor(0x000000);
graphics.fillRect( 0, 0, getWidth(), getHeight() );
}
public void run(){
int w = getWidth();
int h = getHeight() - 1;
while( thread == Thread.currentThread() ){
// récupération des evennements touches
// avec getKeyStates();
// Ensuite on dessine un truc
graphics.setColor(0x000000);
graphics.fillRect( 0, 0, getWidth(), getHeight() );
//.. etc graphics...... tout ce qu'il faut faire pour dessiner
flushGraphics();
// on fait une pause
try {
Thread.currentThread().sleep( delayDePause );
} catch( InterruptedException e ){
; // Faire qqch en cas de pb
}
}
}
// Le canvas est affiché, on lance le thread
protected void showNotify(){
exemple = new Exemple();
thread = new Thread( this );
thread.start();
}
// Le canvas est caché ....
protected void hideNotify(){
thread = null;
}
} |
Partager