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; Command c1=new Command("Kolledzi leht", Command.SCREEN, 1); Command c2=new Command("Jaagupi leht", Command.SCREEN, 1); String aadress=""; public Veebilugeja2(){ try{ t1=new TextBox("Andmed", "Test", 4000, TextField.ANY); t1.addCommand(c1); t1.addCommand(c2); t1.setCommandListener(this); Display.getDisplay(this).setCurrent(t1); }catch(Exception e){ e.printStackTrace(); } } public void commandAction(Command c, Displayable d){ if(c==c2){ aadress="http://www.tlu.ee/~jaagup/"; new Thread(this).start(); } } public void run(){ avaLeht(); } void avaLeht(){ try{ 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.setString(tekst); }catch(Exception ex){ ex.printStackTrace(); } } protected void startApp( ) throws MIDletStateChangeException{} protected void pauseApp( ){} protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{} }