Thread avec Implements Runnable
Bonjour,
Je n'arrive pas a lancer un thread, je sais que c'est inutile ici, mais c'est juste pour l'exemple car la source de mon probléme concerne un serveur Bluetooth, elle est donc beaucoup plus compliqué mais le probléme reste le même.
Code:
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class clientGraphique extends MIDlet implements CommandListener, Runnable {
/*
*On implémente l'interface CommandListener qui nous permet de creer
*des boutons et de reagir en fonction de leur utilisation
*/
private Display display;
private Form pagePrincipale;
protected TextField champTexte;
//Pour envoyer le message
private Command commandSend;
//Pour quitter
private Command commandExit;
Thread th;
private clientBT client;
public void run(){
//On récupére l'affichage de l'ecran
display = Display.getDisplay(this);
//On créer la page principale
pagePrincipale = new Form("clientBT");
//A laquelle on ajoute un champ texte de longueur max 255 pouvant contenir n'importe quel caractère
champTexte = new TextField("Envoyer","",255,TextField.ANY);
//On ajoute les boutons a notre page principale
commandSend = new Command("Send",Command.ITEM,1);
pagePrincipale.addCommand(commandSend);
commandExit = new Command("Exit",Command.EXIT,1);
pagePrincipale.addCommand(commandExit);
//On active les boutons
pagePrincipale.setCommandListener(this);
//On affiche la page principale
pagePrincipale.append(champTexte);
display.setCurrent(pagePrincipale);
// client = new clientBT(this);
}
public clientGraphique(){
th = new Thread();
th.start();
}
protected void startApp() throws MIDletStateChangeException {
/************************************\
|*Initialisation interface graphique*|
\************************************/
/*
* th = new Thread();
* th.start();
*/
}
protected void pauseApp() {
}
protected void destroyApp(boolean arg0) {
}
public void commandAction(Command c, Displayable s){
if(c == commandExit)
// appel manuel à la fonction de fermeture
destroyApp(false);
// on demande au manager de fermer l'application
//notifyDestroyed();
if(c == commandSend){
}
}
} |