import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import java.io.*;
public class TaneliArvestus extends MIDlet implements CommandListener{
	Command c1=new Command("Saada", Command.SCREEN, 1);
  	Command c2=new Command("Välju", Command.EXIT, 1);
	Command c3=new Command("Vali punkt", Command.SCREEN, 1);
  	Command c4=new Command("Vali suurus", Command.SCREEN, 1);
  	Command c5=new Command("Valitud", Command.SCREEN,1);
	TextField PLabel=new TextField("Punkt:", "", 15, TextField.UNEDITABLE);
  	TextField SLabel=new TextField("Suurus:", "", 15, TextField.UNEDITABLE);
  	public static TextField value=new TextField("Väärtus:","0",15, TextField.NUMERIC);
  	public static TextField kell=new TextField("Kellaaeg:","0",15, TextField.ANY);
	public static String[] punktid={"Tallinn", "Tartu", "Võru", "Põlva"};
	int[] punkti_ID={1,2,3,4};
	public static String[] suurused={"Õhuniiskus", "Temperatuur"};
	int[] suuruse_ID={1,2};
  	public static List punktilist=new List("Punkti valik", List.EXCLUSIVE, punktid, null);
  	public static List suuruselist=new List("Suuruse valik", List.EXCLUSIVE, suurused, null);
  	Form f=new Form("TaneliArvestus");
  	
  	public TaneliArvestus(){
  		f.append(PLabel);
  		f.append(SLabel);
  		f.append(kell);
  		f.append(value);
  		f.addCommand(c1);
  		f.addCommand(c2);
  		f.addCommand(c3);
  		f.addCommand(c4);
  		f.setCommandListener(this);
  		punktilist.addCommand(c5);
  		punktilist.setCommandListener(this);
  		suuruselist.addCommand(c5);
  		suuruselist.setCommandListener(this);
  		Display.getDisplay(this).setCurrent(f);
  	}
  	
	public void commandAction( Command p1, Displayable p2 ){
   	if(p1==c1){
   		//saatja.saada(kell.getString(), punktilist.getSelectedIndex(), suuruselist.getSelectedIndex(), value.getString());
   		saatja s= new saatja();
   		new Thread (s).start();
   	}
    	if(p1==c2){notifyDestroyed();}
    	if(p1==c3){Display.getDisplay(this).setCurrent(punktilist);}
    	if(p1==c4){Display.getDisplay(this).setCurrent(suuruselist);}
    	if(p1==c5){
    	   PLabel.setString(punktilist.getString(punktilist.getSelectedIndex()));
    	   SLabel.setString(suuruselist.getString(suuruselist.getSelectedIndex()));
    		Display.getDisplay(this).setCurrent(f);	
    	}
  	}
  	
  	
	protected void startApp( ) throws MIDletStateChangeException{}
  	protected void pauseApp( ){}
  	protected void destroyApp( boolean p1 ) throws MIDletStateChangeException{      }
}