IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java ME Discussion :

Comment récupérer une entrée utilisateur + affichage


Sujet :

Java ME

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 60
    Points : 55
    Points
    55
    Par défaut Comment récupérer une entrée utilisateur + affichage
    Bonjour,
    j'aurais aimé avoir quelques idées d'implémentation pour demander à un utilisateur d'entrer une série de nombres, puis d'appuyer sur Ok, et enfin que le programme affiche un résultat issu du traitement de ces nombres.

    Faire quelque chose dans ce genre :



    Code Big2.java : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
     
    public class Big2 extends MIDlet implements CommandListener
    {
      private Command _commandExit;
      private Command _commandScores;
      private Command _commandOK;
      private String[] elements = { "Joueur 1", "Joueur 2", "Joueur 3", "Joueur 4"};
      private List menu = new List("Big2", List.IMPLICIT,
                elements, null);
     
      public Big2()
      {
        _commandExit = new Command("Exit", Command.EXIT,1);
    	_commandScores = new Command("Scores", Command.EXIT,2);
    	_commandOK = new Command("OK", Command.SCREEN,1);
     
    	menu.addCommand(_commandScores);
    	menu.addCommand(_commandExit);
    	menu.setCommandListener(this);
    	menu.addCommand(_commandOK);
    	menu.setCommandListener(this);
      }
      public void startApp()
      {
    	show();
      }
     
      public void pauseApp()
      {
      }
     
      public void destroyApp(boolean unconditional)
      {
      }
     
      public void commandAction(Command c, Displayable d) {
            if (c == _commandExit) {
                destroyApp(true);
                notifyDestroyed();
                return;
            }
     
            /*switch (menu.getSelectedIndex()) {
    			case 0:
                
    				break;
    			case 1:
                
    				break;
    			case 2:
     
    				break;
    			case 3:
     
    				break;
    			default:
     
    				break;
    		}*/
        }
     
     
        void show() {
            Display.getDisplay(this).setCurrent(menu);
        }
     
     
        Displayable getDisplayable() {
            return menu;
        }
    }

    Il y a des modifications à apporter je pense, et des ajouts.
    J'aimerais créer des petites cases dans lesquelles on pourrait taper chaque nombre pour chaque joueur.
    Merci si vous avez quelques idées à m'apporter.

  2. #2
    Membre régulier
    Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2008
    Messages
    80
    Détails du profil
    Informations personnelles :
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2008
    Messages : 80
    Points : 99
    Points
    99
    Par défaut
    Ben déja crée un formulaire ajoute lui des textField et sur le code du boutton OK tu recupere les valeures et tu les traites pour tes résultats.
    Enfin je vois pas trop ce que tu veut.

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Février 2008
    Messages
    60
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 60
    Points : 55
    Points
    55
    Par défaut
    Merci pit'R pan

    Pour ceux que ça intéresse :
    Code Big2.java : Sélectionner tout - Visualiser dans une fenêtre à part
    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);
        }
    }

    Et si vous voulez mettre une icone pour votre Midlet, vous pouvez mettre une image img.png de taille 12*12 (par exemple) dans le répertoire /res.
    Ensuite dans le Wireless Toolkit, spécifiez le chemin de ce fichier dans Settings/Midlets/Icon puis Edit.
    Il ne reste plus qu'à créer le package.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 3
    Dernier message: 17/02/2015, 15h34
  2. [RegEx] comment récupérer une chaine entre deux mots
    Par mat8883 dans le forum Langage
    Réponses: 3
    Dernier message: 14/11/2012, 19h29
  3. Réponses: 0
    Dernier message: 31/05/2011, 19h13
  4. Réponses: 3
    Dernier message: 03/11/2009, 07h19
  5. Réponses: 1
    Dernier message: 19/06/2008, 10h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo