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

class MobiiliLiides extends Thread implements Runnable{
	static String[] nimed=new String[15];
	static String[] punktid=new String[15];
		
	public MobiiliLiides(){
		start();
	}
	
	public void run(){
		try{			
			String aadress="http://localhost:8080/examples/servlet/Andmed";
    		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);
		    
		    int i=0;
		    int rida, punktisumma;
		      while(tekst.length()>2){
			    rida=tekst.indexOf("\n");		//rea lõpp (9)
			    nimed[i] = tekst.substring(0,rida-1);
			    tekst=tekst.substring(rida+1);
			    
			    Tetris_3.valik.append((i+1)+" "+nimed[i],null);
			    i++;			    
			    
			  }
			  //Tetris_3.n=nimed;
			  System.out.println(i);
		}catch(Exception e){
			System.out.println("Viga[MobiiliLiides]:"+e);
		}
			System.out.println("****************NIMED*************");
			for(int i=0; i<nimed.length;i++){
				System.out.println(nimed[i]);
			}
			System.out.println("****************PUNKTID*************");
			for(int i=0; i<punktid.length;i++){
				System.out.println(punktid[i]);
			}
		//Salvestamine.imporditudAndmed(nimed,punktid);
	}
	static String[] nimed(){
		return nimed;
	}
}

