package hello; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import javax.microedition.io.*; import java.io.*; public class HelloMIDlet extends MIDlet implements CommandListener, Runnable { private Command exitCommand; // The exit command private Command cmdVaata; private Display display; // The display for this MIDlet AsukohaLouend louend=new AsukohaLouend(); String aadress="http://localhost:8080/baas1/asukohaloetelu"; public HelloMIDlet() { display = Display.getDisplay(this); exitCommand = new Command("Lahku", Command.EXIT, 0); cmdVaata=new Command("Vaata", Command.SCREEN, 0); louend.lisaAsukoht("-1 30 50 Sass"); louend.lisaAsukoht("-1 30 60 Jass"); } public void run(){ try{ InputStream sisse=Connector.openInputStream(aadress); ByteArrayOutputStream baos=new ByteArrayOutputStream(); int arv=sisse.read(); while(arv!=-1){ baos.write(arv); arv=sisse.read(); } String tekst=new String(baos.toByteArray()); while(tekst.length()>0){ int koht=tekst.indexOf("\n"); if(koht>=0){ louend.lisaAsukoht(tekst.substring(0, koht)); tekst=tekst.substring(koht+1); } else { louend.lisaAsukoht(tekst); tekst=""; } } } catch(Exception ex){ ex.printStackTrace(); } } public void startApp() { louend.addCommand(exitCommand); louend.addCommand(cmdVaata); louend.setCommandListener(this); display.setCurrent(louend); } public void pauseApp() { } public void destroyApp(boolean unconditional) { } public void commandAction(Command c, Displayable s) { if (c == exitCommand) { destroyApp(false); notifyDestroyed(); } if(c==cmdVaata){ new Thread(this).start(); } } }