import javax.microedition.lcdui.*; import javax.microedition.midlet.*; import javax.microedition.io.*; import java.io.*; import java.util.*; public class turism extends MIDlet implements CommandListener, Runnable{ TextBox t1; List valik=new List("Laulu valik", List.EXCLUSIVE); Vector ide= new Vector(); Command c1=new Command("Andmed", Command.SCREEN, 1); Command c2=new Command("Välju", Command.SCREEN, 1); String[] laulud={}; public turism(){ valik.addCommand(c1); valik.setCommandListener(this); veebiLugemine(); } protected void startApp( ) throws MIDletStateChangeException{} protected void pauseApp( ){} protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{} public void veebiLugemine(){ try{ String aadress="http://localhost:8080/examples/servlet/Maakonnad?maakond&otsimine"; 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); while(tekst.length()>0){ int rida=tekst.indexOf("\n"); String id2 = tekst.substring(0,rida); ide.addElement(id2); valik.append(id2,null); tekst=tekst.substring(rida+1); System.out.println("Ide" + id2); } Display.getDisplay(this).setCurrent(valik); }catch(Exception e){ e.printStackTrace(); } } public void run(){ try{ int number= valik.getSelectedIndex(); String sobivid=(String) ide.elementAt(number); sobivid=sobivid.trim(); // sobivid="Valga"; System.out.println(sobivid); //String aadress2="http://localhost:8080/examples/servlet/servlet?maakond="+sobivid; //String aadress2="http://www.tpu.ee/"; String aadress2="http://localhost:8080/examples/servlet/servlet?maakond="+sobivid; System.out.println(aadress2); InputStream sisse2=Connector.openInputStream(aadress2); ByteArrayOutputStream baos2=new ByteArrayOutputStream(); int arv=sisse2.read(); while(arv!=-1){ baos2.write(arv); arv=sisse2.read(); } byte[] b2=baos2.toByteArray(); String tekst2=new String(b2); t1=new TextBox("Andmed", tekst2, tekst2.length(), TextField.ANY); t1.addCommand(c2); t1.setCommandListener(this); Display.getDisplay(this).setCurrent(t1); }catch(Exception e){ e.printStackTrace(); } } public void commandAction( Command p1, Displayable p2 ){ if (p1==c1){ new Thread(this).start(); } if (p1==c2){ veebiLugemine(); } } }