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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class Big2 extends MIDlet implements CommandListener{
private Display display;
private Form debut,fin;
private Command _commandExit, _commandOK, _backCommand;
private TextField j1,j2,j3,j4,j11,j22,j33,j44;
private StringItem calculer;
public Big2(){
display = Display.getDisplay(this);
debut = new Form("Big2");
_commandExit = new Command("Exit", Command.EXIT,1);
_commandOK = new Command("OK", Command.SCREEN,2);
j1 = new TextField("Joueur 1 : ","",3,TextField.DECIMAL);
j2 = new TextField("Joueur 2 : ","",3,TextField.DECIMAL);
j3 = new TextField("Joueur 3 : ","",3,TextField.DECIMAL);
j4 = new TextField("Joueur 4 : ","",3,TextField.DECIMAL);
calculer = new StringItem("", "Calculer", Item.BUTTON);
//calculer.setDefaultCommand(_commandOK);
//calculer.setItemCommandListener(this);
debut.addCommand(_commandExit);
debut.addCommand(_commandOK);
debut.append(j1);
debut.append(j2);
debut.append(j3);
debut.append(j4);
//debut.append(calculer);
debut.setCommandListener(this);
fin = new Form("Résultat");
_backCommand = new Command("Retour", Command.BACK,1);
j11 = new TextField("Joueur 1 : ","",3,TextField.UNEDITABLE);
j22 = new TextField("Joueur 2 : ","",3,TextField.UNEDITABLE);
j33 = new TextField("Joueur 3 : ","",3,TextField.UNEDITABLE);
j44 = new TextField("Joueur 4 : ","",3,TextField.UNEDITABLE);
fin.append(j11);
fin.append(j22);
fin.append(j33);
fin.append(j44);
fin.addCommand(_backCommand);
AlertType.INFO.playSound(display);
AlertType.WARNING.playSound(display);
fin.setCommandListener(this);
}
public void startApp(){
display.setCurrent(debut);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
public void commandAction(Command c, Displayable d){
if (c==_commandExit){
destroyApp(true);
notifyDestroyed();
return;
}else if (c==_commandOK){
resultat();
}else if (c==_backCommand ){
j1.delete(0,j1.size());
j2.delete(0,j2.size());
j3.delete(0,j3.size());
j4.delete(0,j4.size());
display.setCurrent(debut);
}
}
private int getNumber(TextField t){
String s = t.getString();
int n = Integer.parseInt(s);
return n;
}
private void resultat(){
int a = getNumber(j1);
int b = getNumber(j2);
int c = getNumber(j3);
int d = getNumber(j4);
if(a>=10 && a<13) a*=2;
if(b>=10 && b<13) b*=2;
if(c>=10 && c<13) c*=2;
if(d>=10 && d<13) d*=2;
if(a==13) a*=3;
if(b==13) b*=3;
if(c==13) c*=3;
if(d==13) d*=3;
int aa = (b-a)+(c-a)+(d-a);
int bb = (a-b)+(c-b)+(d-b);
int cc = (a-c)+(b-c)+(d-c);
int dd = (a-d)+(b-d)+(c-d);
String res1 = Integer.toString(aa);
String res2 = Integer.toString(bb);
String res3 = Integer.toString(cc);
String res4 = Integer.toString(dd);
j11.setString(res1);
j22.setString(res2);
j33.setString(res3);
j44.setString(res4);
display.setCurrent(fin);
}
} |
Partager