import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class saatja extends Thread{
  static TextBox t1;
  
  public void run(){
  		String aeg=TaneliArvestus.kell.getString();
  		String value=TaneliArvestus.value.getString();
  		int pid=TaneliArvestus.punktilist.getSelectedIndex();
  		int sid=TaneliArvestus.suuruselist.getSelectedIndex();
  		
  		try{
    		String aadress="http://localhost:8080/TaneliArvestus/servlet/kirjutaja?kell="+aeg+"&pid="+pid+"&sid="+sid+"&tulemus="+value;
    		System.out.println(aadress);
    		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);
    		//Display.getDisplay(TaneliArvestus).setCurrent(t1);
   	}catch(Exception e){e.printStackTrace();}
  }
  /*
  public saatja(){
  		String aeg=TaneliArvestus.kell.getString();
  		String value=TaneliArvestus.value.getString();
  		int pid=TaneliArvestus.punktilist.getSelectedIndex();
  		int sid=TaneliArvestus.suuruselist.getSelectedIndex();
  		
  		try{
    		String aadress="http://localhost:8080/TaneliArvestus/kirjutaja?kell="+aeg+"&pid="+pid+"&sid="+sid+"&tulemus="+value;
    		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);
    		//Display.getDisplay(TaneliArvestus).setCurrent(t1);
   	}catch(Exception e){e.printStackTrace();}
  	}
  */
  /*
  public static void saada(String aeg, int pid, int sid, String value){
   try{
    String aadress="http://localhost:8080/TaneliArvestus/kirjutaja?kell="+aeg+"&pid="+pid+"&sid="+sid+"&tulemus="+value;
    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(TaneliArvestus).setCurrent(t1);
   }catch(Exception e){
     e.printStackTrace();
   }
  }
  */
  protected void startApp( ) throws MIDletStateChangeException{}
  protected void pauseApp( ){}
  protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{}
}