Blogia
guille9020

Mis datos Http

Mis datos Http

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

public class Datos extends MIDlet implements CommandListener {

    Display display = null;
    List menu = null;
    TextBox t = null;
    private String url1 = "http://newworldpublic.vacau.com/jimmy/datos1.html";
    private String url2 = "http://newworldpublic.vacau.com/jimmy/datos.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 Datos() {
    }

    public void startApp() throws MIDletStateChangeException {
        display = Display.getDisplay(this);

        menu = new List("Mi informacion", Choice.IMPLICIT);
        menu.append("Mis datos", null);
        menu.append("Info extra", 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 Infoextra() {
        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);
            }

            t = new TextBox("Mis datos...", b.toString(), 1024, 0);
            t.addCommand(backCommand);
            t.setCommandListener(this);
        } finally {
            if (is != null) {
                is.close();
            }
            if (c != null) {
                c.close();
            }
        }
        display.setCurrent(t);
    }

    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);
            }
            t = new TextBox("Extra...", 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 testItem1() {
        misDatos();
        currentMenu = "Mis datos";
    }

    public void testItem2() {
        Infoextra();
        currentMenu = "Info extra";
    }

    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("Info extra")) {
            }
        } else {
            List down = (List) display.getCurrent();
            switch (down.getSelectedIndex()) {
                case 0:
                    testItem1();
                    break;
                case 1:
                    testItem2();
                    break;
            }
        }
    }

    public void pauseApp() {
        display = null;
    menu = null;
    //input = null;
    }

    public void destroyApp(boolean incondicional) {
        notifyDestroyed();
    }
}

No puedo trepar todas las fotos profe y no utilice mi cel porque no lo soporto no se porque!! :$

0 comentarios