menu.
java :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello
;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.ChoiceGroup;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.*;
/**
* @author Jason
*/
public class Menu extends MIDlet
implements CommandListener
{
private Display display
;
private Form menu, showContact
;
private ChoiceGroup choix, affichage, delMod
;
private String[] optionChoix =
{"Ajouter un contact",
"Voir les contacts"};
private String[] optionDelMod =
{"Modifier le contact",
"Supprimer le contact"};
private Command okCommand, exitCommand, retourShowContactCommand, validDelModCommand
;
private Form addContact, reussite, contact
;
private TextField nom, prenom, mail
;
private Command addCommand, retourCommand, menuCommand, quitCommand, showCommand
;
private Alert erreur
;
private Vector list
;
private calabo Calabo
;
private Integer id
;
private int i =
0;
public Menu() {
//Init du Vector
list =
new Vector();
//Création menu
menu =
new Form
("Menu");
menu.
append("Welcome");
choix =
new ChoiceGroup
("Votre choix : ", ChoiceGroup.
EXCLUSIVE, optionChoix,
null);
menu.
append(choix
);
okCommand =
new Command
("Valider", Command.
OK,
1);
exitCommand =
new Command
("Quitter", Command.
EXIT,
1);
retourCommand =
new Command
("Retour", Command.
BACK,
1);
menu.
addCommand(okCommand
);
menu.
addCommand(exitCommand
);
menu.
setCommandListener(this);
}
public void startApp
() {
display = Display.
getDisplay(this);
display.
setCurrent(menu
);
}
public void pauseApp
() {
}
public void destroyApp
(boolean unconditional
) {
}
public void commandAction
(Command c, Displayable d
) {
if (c.
getLabel().
equals("Valider")) {
switch (choix.
getSelectedIndex()) {
case 0:
AddContact
();
break;
case 1 : ShowContact
(); break;
}
} else if (c.
getLabel().
equals("Quitter")) {
destroyApp
(true);
notifyDestroyed
();
} else if (c.
getLabel().
equals("Ajouter")) {
if ((nom.
getString().
equals("")) ||
(prenom.
getString().
equals("")) ||
(mail.
getString().
equals(""))) {
erreur =
new Alert
("Erreur",
"Erreur dans les champs",
null, AlertType.
ERROR);
erreur.
addCommand(retourCommand
);
erreur.
setCommandListener(this);
display.
setCurrent(erreur
);
} else {
Reussite
();
}
} else if (c.
getLabel().
equals("Retour au menu")) {
display.
setCurrent(menu
);
} else if (c.
getLabel().
equals("Retour")) {
display.
setCurrent(addContact
);
} else if (c.
getLabel().
equals("Voir le contact")) {
Contact
();
} else if (c.
getLabel().
equals("Retour au contact")) {
ShowContact
();
} else if (c.
getLabel().
equals("Valider le choix")) {
Form test =
new Form
("Test");
}
}
public void AddContact
() {
addContact =
new Form
("Ajouter un Contact");
nom =
new TextField("Nom : ",
"",
20,
TextField.
ANY);
addContact.
append(nom
);
prenom =
new TextField("Prenom : ",
"",
20,
TextField.
ANY);
addContact.
append(prenom
);
mail =
new TextField("Mail : ",
"",
20,
TextField.
ANY);
addContact.
append(mail
);
addCommand =
new Command
("Ajouter", Command.
OK,
1);
addContact.
addCommand(addCommand
);
exitCommand =
new Command
("Retour au menu", Command.
EXIT,
1);
addContact.
addCommand(exitCommand
);
addContact.
setCommandListener(this);
display.
setCurrent(addContact
);
}
public void Reussite
() {
reussite =
new Form
("Réussite");
//Enregistrement
Calabo =
new calabo
(nom.
getString(), prenom.
getString(), mail.
getString());
list.
addElement(Calabo
);
reussite.
append("Contact Sauvegardé");
//Commandes
menuCommand =
new Command
("Retour au menu", Command.
EXIT,
1);
reussite.
addCommand(menuCommand
);
quitCommand =
new Command
("Quitter", Command.
EXIT,
1);
reussite.
addCommand(quitCommand
);
reussite.
setCommandListener(this);
display.
setCurrent(reussite
);
}
public void ShowContact
() {
String[] tableau =
new String[list.
size()];
Enumeration e = list.
elements();
while (e.
hasMoreElements())
{
Calabo =
(calabo
)e.
nextElement();
tableau
[i
] = Calabo.
getNom();
i++
;
}
affichage =
new ChoiceGroup
("Affichage :", ChoiceGroup.
EXCLUSIVE, tableau,
null);
showContact =
new Form
("Affichage");
showContact.
append(affichage
);
//Commandes
showCommand =
new Command
("Voir le contact", Command.
OK,
1);
showContact.
addCommand(showCommand
);
showContact.
addCommand(retourCommand
);
showContact.
setCommandListener(this);
display.
setCurrent(showContact
);
}
public void Contact
(){
contact =
new Form
("Contact");
contact.
append(Calabo.
getNom());
contact.
append(Calabo.
getPrenom());
contact.
append(Calabo.
getMail());
delMod =
new ChoiceGroup
("Votre choix : ", ChoiceGroup.
EXCLUSIVE, optionDelMod,
null);
contact.
append(delMod
);
//Commande
retourShowContactCommand =
new Command
("Retour au contact", Command.
BACK,
1);
validDelModCommand =
new Command
("Valider le choix", Command.
OK,
1);
contact.
addCommand(retourShowContactCommand
);
contact.
addCommand(validDelModCommand
);
contact.
setCommandListener(this);
display.
setCurrent(contact
);
}
}
-------------------------------------------------------------------
calabo.
java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello
;
import javax.microedition.lcdui.TextField;
/**
*
* @author Jason
*/
public class calabo
{
private String nom, prenom, mail
;
public calabo
(String nom,
String prenom,
String mail
) {
this.
nom = nom
;
this.
prenom = prenom
;
this.
mail = mail
;
}
public String getMail
() {
return mail
;
}
public void setMail
(String mail
) {
this.
mail = mail
;
}
public String getNom
() {
return nom
;
}
public void setNom
(String nom
) {
this.
nom = nom
;
}
public String getPrenom
() {
return prenom
;
}
public void setPrenom
(String prenom
) {
this.
prenom = prenom
;
}
}