// contient les éléments de base
import javax.microedition.midlet.*;
// contient les éléments permettant de gérer l'interface
import javax.microedition.lcdui.*;
public class Hello_world extends MIDlet implements CommandListener
{
private Display _display;
private TextField _textField1;
private Command _commandExit;
private Form _form1;
private StringItem Msg;
public Hello_world()
{
// fait un lien avec l'affichage
_display = Display.getDisplay(this);
// creation d'un objet formulaire sur lequel on peut placer des composants
_form1 = new Form("Test de HelloWorld");
// creation d'un bouton pour sortir du programme
_commandExit = new Command("Exit", Command.SCREEN,1);
// creation d'un champ de texte contenant notre Hello World
_textField1 = new TextField("","Hello World !",30,TextField.PLAIN);
//
Msg=new StringItem("","test");
// ajout des composants au formulaire
_form1.addCommand(_commandExit);
_form1.append(_textField1);
_form1.append(Msg);
_form1.setCommandListener(this);
try
{
Image im=Image.createImage("/images/test.png");
_form1.append(new ImageItem(null,im,ImageItem.LAYOUT_CENTER,null));
_display.setCurrent(_form1);
}
catch(java.io.IOException e)
{
System.err.println("Impossible de trouver ou lire l'image");
}
}
// évènement exécuté au démarrage de l'application
public void startApp()
{
// affichage du formulaire
_display.setCurrent(_form1);
}
// évènement exécuté lors de la mise en pause de l'application
public void pauseApp()
{
}
// évènement exécuté lorsque l'application se termine
public void destroyApp(boolean unconditional)
{
}
public void commandAction(Command c, Displayable s)
{
// lors du clic sur le bouton Exit
if (c == _commandExit)
{
// appel manuel à la fonction de fermeture
destroyApp(false);
// on demande au manager de fermer l'application
notifyDestroyed();
}
}
}
Partager