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
| import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.m2g.SVGAnimator;
import javax.microedition.m2g.SVGEventListener;
import javax.microedition.m2g.SVGImage;
import javax.microedition.m2g.ScalableGraphics;
import javax.microedition.midlet.*;
import org.w3c.dom.*;
import org.w3c.dom.events.*;
import org.w3c.dom.svg.*;
public class MyApp extends MIDlet{
private Canvas canvas;
protected SVGImage svgImage;
// Création d'une instance graphique
protected ScalableGraphics sg=ScalableGraphics.createInstance();
private static String command,module,edited,login,password;
private boolean checked=false;
private TextBox textBox;
private final Command start=new Command("Start",Command.OK,2);
private final Command back=new Command("Back",Command.EXIT,1);
private final Command ok=new Command("ok",Command.OK,2);
private final Command exit=new Command("Save",Command.OK,2);
private MIDlet midlet=this;
private CommandListener myCommandListener=new CommandListener(){
public void commandAction(Command c, Displayable d) {
if(c==exit){
notifyDestroyed();
}
else{
System.out.println("Saw the command: " + c);
}
}
};
public MyApp(){
}
public void startApp(){
module="logo";
// Création du canevas
canvas=new Canvas(){
private double heightRatio=getHeight()/400.0;
private double widthRatio=getWidth()/240.0;
public void pointerPressed(int x,int y){
if(module.equals("logo")){
module="login";
repaint();
}
else if(module.equals("login")){
if(y>100*heightRatio&&y<150*heightRatio&&x>20*widthRatio&&x<220*widthRatio){
textBox=new TextBox("Login :",null,50,TextField.ANY);
textBox.addCommand(exit);
edited="login";
textBox.setCommandListener(myCommandListener);
Display.getDisplay(midlet).setCurrent(textBox);
}
else if(y>170*heightRatio&&y<220*heightRatio&&x>20*widthRatio&&x<220*widthRatio){
textBox=new TextBox("Password :",null,50,TextField.ANY);
edited="password";
textBox.addCommand(exit);
Display.getDisplay(midlet).setCurrent(textBox);
}
else if(y>240*heightRatio&&y<290*heightRatio&&x>20*widthRatio&&x<40*widthRatio){
if(checked==true){
checked=false;
}
else{
checked=true;
}
}
else if(y>310*heightRatio&&y<360*heightRatio&&x>20*widthRatio&&x<220*widthRatio){
//Connect();
}
}
}
public void paint(Graphics g){
// Définition de la qualité du rendu
sg.setRenderingQuality(2);
// Définition de la couleur du canevas
g.setColor(219,238,255);
// Définition du background du canevas
g.fillRect(0,0,getWidth(),getHeight());
// Ajout de l'instance graphique au canevas
sg.bindTarget(g);
try{
// Création de l'image
svgImage=(SVGImage)SVGImage.createImage((InputStream)getClass().getResourceAsStream("/"+module+".svg"),null);
// Définitions des dimensions de l'image
svgImage.setViewportWidth(getWidth());
svgImage.setViewportHeight(getHeight());
// Ajout de l'image au canevas (rendu)
sg.render(0,0,svgImage);
}
catch(Exception e){}
// Libération de l'instance graphique
sg.releaseTarget();
}
};
canvas.setFullScreenMode(true);
// Affichage du canevas
Display.getDisplay(this).setCurrent(canvas);
}
public void pauseApp(){
}
public void destroyApp(boolean unconditional){
}
} |
Partager