import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import javax.microedition.io.*; import java.io.*; public class Veebilugeja2 extends MIDlet implements CommandListener, Runnable { TextBox t1; Form f=new Form("Veebivalik"); Command c1=new Command("koduleht", Command.SCREEN, 1); Command c2=new Command("ilmateade", Command.SCREEN, 2); String leheaadress=""; public Veebilugeja2(){ f.addCommand(c1); f.addCommand(c2); f.setCommandListener(this); Display.getDisplay(this).setCurrent(f); } public void commandAction(Command p1, Displayable d){ if(p1==c1){ leheaadress="http://www.tlu.ee/~jaagup/"; } if(p1==c2){ leheaadress="http://www.ilm.ee/"; } new Thread(this).start(); } public void run(){ try{ String aadress=leheaadress; InputStream sisse=Connector.openInputStream(aadress); ByteArrayOutputStream baos=new ByteArrayOutputStream(); int arv=sisse.read(); while(arv!=-1){ baos.write(arv); arv=sisse.read(); } byte[] b=baos.toByteArray(); String tekst=new String(b); t1=new TextBox("Andmed", tekst, tekst.length(), TextField.ANY); Display.getDisplay(this).setCurrent(t1); }catch(Exception e){ e.printStackTrace(); } } protected void startApp( ) throws MIDletStateChangeException{} protected void pauseApp( ){} protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{} }