~ M i R t H a ~

~ M i R t H a ~

sábado, 26 de marzo de 2011

MIDLET

Codigo

/*


* To change this template, choose Tools Templates


* and open the template in the editor.


*/



import java.io.*;


import javax.microedition.midlet.*;


import javax.microedition.io.*;


import javax.microedition.lcdui.*;



/**


* @author Mirtha


*/


public class MisDatos extends MIDlet implements CommandListener {


Display display = null;


List menu = null;


TextBox input = null;


TextBox m = null;



private String url1 = "http://mejormusica.comeze.com/datos.html";


private String url2 = "http://mejormusica.comeze.com/bio.html";



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 MisDatos() {


}



public void startApp() throws MIDletStateChangeException {


display = Display.getDisplay(this);



menu = new List("Menu Items", Choice.IMPLICIT);


menu.append("Mis Datos", null);


menu.append("Biografia y foto", null);


menu.addCommand(exitCommand);


menu.setCommandListener(this);



mainMenu();


}



void mainMenu() {


display.setCurrent(menu);


currentMenu = "Main";


}



public void misDatos() {


try {


download(url1);



} catch(IOException e) {


System.out.println("IOException: " + e);


}


}



public void Biografia(){


try {


download1(url2);


} catch(IOException e) {


System.out.println("IOException: " + e);


}


}



private void download (String url1) throws IOException {


StringBuffer b = new StringBuffer();


InputStream is = null;


HttpConnection c = null;



try {


long len = 0;


int ch = 0;



c = (HttpConnection)Connector.open(url1);


is = c.openInputStream();



while((ch = is.read()) != -1) {


b.append((char)ch);


}



m = new TextBox("Mis datos...", b.toString(), 1024, 0);


m.addCommand(backCommand);


m.setCommandListener(this);



} finally {


if (is != null)


is.close();


if (c != null)


c.close();


}


display.setCurrent(m);


}



private void download1 (String url2) throws IOException {


StringBuffer b = new StringBuffer();


InputStream is = null;


HttpConnection c = null;



try {


long len = 0;


int ch = 0;



c = (HttpConnection)Connector.open(url2);


is = c.openInputStream();



while((ch = is.read()) != -1) {


b.append((char)ch);


}



m = new TextBox("Adicional...", b.toString(), 1024, 0);


m.addCommand(backCommand);


m.setCommandListener(this);


} finally {


if (is != null)


is.close();


if (c != null)


c.close();


}


display.setCurrent(m);


}



public void testItem1() {


misDatos();


currentMenu = "Mis Datos";


}





public void testItem2() {


Biografia();


currentMenu = "Biografia y foto";


}



public void commandAction(Command c, Displayable d) {


String label = c.getLabel();


if (label.equals("Exit")) {


destroyApp(true);



} else if (label.equals("Back")) {


mainMenu();


if (currentMenu.equals("Mis Datos") currentMenu.equals("Biografia y foto")) {


}



} else {


List down = (List)display.getCurrent();


switch (down.getSelectedIndex()) {


case 0: testItem1();break;


case 1: testItem2();break;


}


}


}



public void pauseApp() {



}


public void destroyApp(boolean incondicional) {



}


}

MENU
MIS DATOS DATOS ADICIONALES

miércoles, 2 de marzo de 2011





CODIGO


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("Mirtha Chan",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 metodo paint
};
//Creamos el comando salir
salir=new Command("Salir",Command.EXIT, 3);

//añadimos el comando al Canvas y activamos al 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 Activo a Pausado
protected void pauseApp( ) {
}

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

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