sábado, 26 de marzo de 2011




M I C O D I G O

import java.io.*;
import javax.microedition.lcdui.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
public class Principal extends MIDlet implements CommandListener {
Display display = null;

private String url = "http://extremadamenteeinnecesariamentelargo.web44.net/docs/datos-pajaro";
private String url2 = "http://extremadamenteeinnecesariamentelargo.web44.net/docs/datos-adicional";

List menu = null;
TextBox input = null;
TextBox t=null;
static final Command backCommand = new Command("Back", Command.BACK, 0);
static final Command mainMenuCommand = new Command("Main", Command.SCREEN,1);
static final Command exitCommand = new Command("Exit", Command.STOP, 2);
String currentMenu = null;
public Principal() { }
public void startApp() throws MIDletStateChangeException { display = Display.getDisplay(this);
menu = new List("Menu Items", Choice.IMPLICIT);
menu.append("Datos generales", null);
menu.append("Informacion Adicional", null);


menu.addCommand(exitCommand);
menu.setCommandListener(this);
mainMenu();

}
public void download (String url) throws IOException{
StringBuffer b= new StringBuffer();
InputStream is=null;
HttpConnection c=null;

try {
long len =0;
int ch=0;

c= (HttpConnection)Connector.open(url);
is = c.openInputStream();
while ((ch=is.read()) !=-1){
b.append((char)ch);
}
t = new TextBox("Hola..." ,b.toString(), 1024,0);
t.addCommand(backCommand);

t.setCommandListener(this);

} finally {
if(is !=null)
is.close();
if(c !=null)
c.close();
}

display.setCurrent(t);

}
public void pauseApp() {
display = null;
menu = null;
input = null;
}
public void destroyApp(boolean unconditional) {

notifyDestroyed();
}
void mainMenu() {
display.setCurrent(menu);
currentMenu = "Main";
}
public void testIteml() {
display = Display.getDisplay(this);
try{
download(url);
} catch(IOException e){
System.out.println("IOException" + e);
}
}
public void testItem2() {
display = Display.getDisplay(this);
try{
download(url2);
} catch(IOException e){
System.out.println("IOException" + e);
}
}


public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("Exit")) {
destroyApp(true);
}
if (label.equals("Back")) {
mainMenu();
if(currentMenu.equals("Datos generales") ||
currentMenu.equals("Informacion Adicional") ) {


}
} else {
List down = (List)display.getCurrent();
switch(down.getSelectedIndex()) {
case 0: testIteml();break;
case 1: testItem2();break;


}
}
}
}

martes, 1 de marzo de 2011

mi tarjeta


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class tarjeta extends MIDlet implements CommandListener {
private Display display;
private Command salir;
private Canvas micanvas;

//Constructor
public tarjeta() {

//Cogemos el display
display=Display.getDisplay(this);

//Creamos la pantalla principal
micanvas = new Canvas() {
private int width;
private int height;

public void paint (Graphics g){
width=getWidth();
height=getHeight();

//Pintamos la pantalla de negro
g.setColor(0,0,0);
g.fillRect(0,0,width,height);

//Leemos una imagen desde un fichero y la mostramos
try {
Image imagen=Image.createImage("/logo.png");
g.drawImage(imagen,width/2,height/2,(Graphics.VCENTER | Graphics.HCENTER));
g.setColor(255,255,255);
//g.setStrokeStyle(Graphics.SOLID);
g.drawString("juan andres--------santamariajuan1958@hotmail.com",10,10,(Graphics.BASELINE |
Graphics.LEFT));
g.drawString("",10,10,(Graphics.BASELINE |
Graphics.LEFT));



} catch (java.io.IOException e) {
g.setColor(255,255,255);
g.setStrokeStyle(Graphics.SOLID);
g.drawString("Fallo al leer logo.png",0,height/2,(Graphics.BASELINE | Graphics.LEFT));

}
}//fin del metodo paint
};
//Creamos el comando salir
salir=new Command("Salir",Command.EXIT,3);

//añadimos el comando al Canvas y activamos el oyente
micanvas.addCommand(salir);
micanvas.setCommandListener(this);
}

//Metodo que se llama cuando pasamos de Pausado a Activo
protected void startApp( ) {
display.setCurrent(micanvas);
}

//Metodo que se llama cuando pasamos de Activado a Pausado
protected void pauseApp( ) {
display.setCurrent(micanvas);
}

//Metodo que se llama cuando se destruye el midlet
protected void destroyApp(boolean incondicional) {
}

//Metodo para el tratamiento de datos del teclado
public void commandAction(Command c, Displayable d) {
//Miramos si nos salimos o mostramos alerta
if (c==salir) {
destroyApp(true);
notifyDestroyed();
} else System.out.println("Otro comando pulsado");
}
}