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 :

Récupérer KeyCode Flèches


Sujet :

Java ME

  1. #1
    Futur Membre du Club
    Inscrit en
    Février 2008
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 15
    Points : 9
    Points
    9
    Par défaut Récupérer KeyCode Flèches
    Bonjour

    Je cherche à faire une petite application sur un PDA en JAVA et pour cela, j'ai besoin d'utiliser les flèches et de paramètrer leurs fonctions. Cependant je ne trouve pas leur KeyCode.

    Merci

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 88
    Points : 60
    Points
    60
    Par défaut
    Tiens j'avais trouvé sur le net le code d'une petite application qui t'indiques les codes des touches :

    KeyCode.java :
    Code : 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
    import javax.microedition.lcdui.Display;
    import javax.microedition.midlet.MIDlet;
     
    /**
     * A simple MIDlet to display the Key Codes of the handset.
     */
    public class KeyCode extends MIDlet {
     
    	public void startApp() {
    		KeyCodeCanvas kcc = new KeyCodeCanvas(this);
    		Display.getDisplay(this).setCurrent(kcc);
    	}
     
    	public void pauseApp() {
    	}
     
    	public void destroyApp(final boolean unconditional) {
    	}
     
    	public void quit() {
    		notifyDestroyed();
    	}
     
    }
    KeyCodeCanvas.java :
    Code : 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
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
     
    /**
     * A canvas that displays the key code corresponding to the key pressed.
     */
    public class KeyCodeCanvas extends Canvas {
     
    	private KeyCode myMIDlet;
    	private String myCurrentCode = "none";
    	private boolean myPoundPressed = false;
     
    	/**
             * just set a handle back to the MIDlet.
             */
    	public KeyCodeCanvas(final KeyCode midlet) {
    		this.myMIDlet = midlet;
    	}
     
    	/**
             * Paint the key code corresponding to the key that has been pressed.
             * 
             * Note that this is far from optimized!!!
             */
    	public void paint(final Graphics g) {
    		// get the size of the painting region:
    		int width = getWidth();
    		int hcenter = width / 2;
    		int height = getHeight();
     
    		// clear the screen by coloring everything white:
    		g.setColor(0xffffff);
    		g.fillRect(0, 0, width, height);
     
    		// write the instructions at the top in black:
    		g.setColor(0x000000);
    		Font font = g.getFont();
    		int fontHeight = font.getHeight();
    		g.drawString("to exit", hcenter, 0, Graphics.TOP | Graphics.HCENTER);
    		g.drawString("press # twice", hcenter, fontHeight + 1, Graphics.TOP | Graphics.HCENTER);
     
    		// Now draw the key code number:
    		g.drawString(this.myCurrentCode, hcenter, 2 * (fontHeight + 1), Graphics.TOP
    				| Graphics.HCENTER);
     
    	}
     
    	/**
             * Record the keycode.
             */
    	public void keyPressed(final int keyCode) {
    		// check for the pound key, and if this is
    		// the second pound in a row, quit:
    		if (keyCode == Canvas.KEY_POUND) {
    			if (this.myPoundPressed) {
    				this.myMIDlet.quit();
    				return;
    			} else {
    				this.myPoundPressed = true;
    			}
    		} else {
    			this.myPoundPressed = false;
    		}
    		// Now set the key code:
    		this.myCurrentCode = (new Integer(keyCode)).toString();
    		// Now display it:
    		repaint();
    	}
     
    }

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2006
    Messages : 88
    Points : 60
    Points
    60
    Par défaut
    de rien au fait

  4. #4
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2006
    Messages
    137
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2006
    Messages : 137
    Points : 158
    Points
    158
    Par défaut
    oui guenievre, yen a qui sont franchement desesperant

  5. #5
    Futur Membre du Club
    Inscrit en
    Février 2008
    Messages
    15
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 15
    Points : 9
    Points
    9
    Par défaut
    Je suis vraiment désolée, mais j'étais persuadée d'avoir répondu.
    Merci beaucoup pour ta réponse si rapide.

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

Discussions similaires

  1. Récupérer keyCode IE - Touche clic
    Par omageus dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 28/09/2009, 15h37
  2. [event.keyCode] Détection de la flèche bas sous Opera
    Par bigben89 dans le forum Général JavaScript
    Réponses: 17
    Dernier message: 26/11/2008, 14h02
  3. Récupérer 10 nb différents avec un calcul aléatoire
    Par BXDSPORT dans le forum Langage
    Réponses: 3
    Dernier message: 04/08/2002, 02h35
  4. Réponses: 11
    Dernier message: 23/07/2002, 14h33
  5. Comment récupérer une adresse MAC ?
    Par psau dans le forum Développement
    Réponses: 7
    Dernier message: 19/07/2002, 17h26

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