Bonjour
Je suis en train de développer une petite application sur appareils mobile qui affiche différentes listes en fonction des touches appuyées.
Cependant, une fois que la liste est affichée, je n'ai plus accès aux keyPressed. Je me doute qu'il y a une concurrence entre les deux keyPressed, mais comment afficher ma liste alors tout en laissant la main au keyPressed ?
Voici le code de KeyCode.java
et celui du 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 import javax.microedition.lcdui.Choice; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.List; import javax.microedition.midlet.MIDlet; public class KeyCode extends MIDlet { //implements CommandListener{ List But; List Instruction; /* private Command exitCommand = new Command("Exit", Command.BACK, 1); private Command playCommand = new Command("Play", Command.OK, 1); */ public Display display; KeyCodeCanvas kcc = new KeyCodeCanvas(this); public void startApp() { //super(); display = Display.getDisplay(this); initPlayList(); display.setCurrent(kcc); //But.addCommand(exitCommand); //display.setCurrent(But); } public void pauseApp() { } public void destroyApp(boolean unconditional) { display.setCurrent(null); } /* public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(true); notifyDestroyed(); } else if ((s == But && c == List.SELECT_COMMAND) || c == playCommand) { affiche_liste(); } } */ public void affiche_liste(){ display.setCurrent(Instruction); } private void initPlayList() { //theList = new List("MIDP Audio Player", Choice.IMPLICIT); But = new List("Liste des objectifs", Choice.IMPLICIT); But.append("B1", null); But.append("B2", null); But.append("B3", null); /*But.addCommand(exitCommand); But.addCommand(playCommand); But.setCommandListener(this); */ String LInst[] = {"I1", "I2", "I3"}; Instruction = new List("Liste des instructions", Choice.IMPLICIT, LInst, null); } public void quit() { notifyDestroyed(); } }
Merci
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
72
73
74
75
76
77
78
79
80
81
82 import javax.microedition.lcdui.Canvas; 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; public int myCurrentTouche = 0; /** * 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) { } public void developper() { myMIDlet.display.setCurrent(myMIDlet.Instruction); } public void ranger (){ myMIDlet.display.setCurrent(myMIDlet.But); } public void item_precedent(){ } public void item_suivant(){ } public void precedent(){ } public void menu(){ } public void keyPressed(final int keyCode) { this.myCurrentTouche = keyCode; System.out.println("Delete failed: " + this.myCurrentTouche); // flèche droite if (this.myCurrentTouche == -4 ) { developper(); } // flèche gauche if (this.myCurrentTouche == -3 ) { ranger(); } // bouton central if (this.myCurrentTouche == -5 ) { menu(); } // bouton back if (this.myCurrentTouche == -6 ) { precedent(); } // flèche haut if (this.myCurrentTouche == -1){ item_precedent(); } if (this.myCurrentTouche == -2){ item_suivant(); } repaint(); } }
Partager