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


public class Tetris_3 extends MIDlet implements CommandListener{
	static String[] n={};
	static Louend							c=new Louend();
	TextField 						tf1=new TextField("Nimi", "", 7, TextField.ANY);
	Command 						c1=new Command("Sisesta oma nimi", Command.SCREEN, 1);
	Command 						c11=new Command("Parimad mängijad - TOP15", Command.SCREEN, 1);
  	Command 						c2=new Command("Välju", Command.EXIT, 1);
  	Command 						c3=new Command("Tagasi", Command.EXIT, 1);
  	Command 						c4=new Command("Salvesta nimi", Command.SCREEN, 1);
  	Command 						c5=new Command("Tagasi", Command.EXIT, 1);  	
  	Form 							f=new Form("Tetrise seaded");  	  	
  	static Command 						c6=new Command("Saada nimi veebi", Command.SCREEN, 1);
  	static List							valik=new List("TOP-15", List.EXCLUSIVE,n,null);  
  	MobiiliLiides 					AndmedVeebist;	
  	MobiiliLiides2					AndmedVeebi;	
  	String player="mangija";
	public Tetris_3(){				
	    c.addCommand(c1);
	    c.addCommand(c11);
	    c.addCommand(c2);
	    c.setCommandListener(this);		    
	    Display.getDisplay(this).setCurrent(c);	    
	    f.append(tf1);
	    f.addCommand(c3);
	    f.addCommand(c4);
	    f.setCommandListener(this);		    
	    valik.setCommandListener(this);
	    valik.addCommand(c5);
	}		
	protected void destroyApp(boolean a)throws MIDletStateChangeException{}
	protected void pauseApp(){}	
	protected void startApp()throws MIDletStateChangeException{}
	
	public void commandAction( Command p1, Displayable p2 ){
    	if(p1==c1){
    		Display.getDisplay(this).setCurrent(f);
    		c.paus=true;
    	}
    	if(p1==c11){
    		c.paus=true;
    		AndmedVeebist=new MobiiliLiides();  
    		Display.getDisplay(this).setCurrent(valik);
    	}
     	if(p1==c2){
       		notifyDestroyed();
     	}
     	if(p1==c3){
       		Display.getDisplay(this).setCurrent(c);
       		c.paus=false;
     	}
     	if(p1==c4){     		     	
     		String mangija=String.valueOf(tf1.getString());
     		player=mangija;
     		if(mangija.length()<=6){
     			for(int i=0;i<=7-mangija.length();i++)
     			{
     				mangija+=" ";
     			}
     		}     		
       		c.nihuta.nimi=mangija;
       		Display.getDisplay(this).setCurrent(c);
       		c.paus=false;
     	}
     	if(p1==c5){
       		Display.getDisplay(this).setCurrent(c);
       		c.paus=false;
     	}
     	if(p1==c6){
       		System.out.println("njaa");
       		System.out.println(c.nihuta.nimi+"|");
       		System.out.println(c.nihuta.skoor+"|");
       		AndmedVeebi=new MobiiliLiides2(player,String.valueOf(c.nihuta.skoor));  
       		c.removeCommand(c6);
       		c.removeCommand(c1);
     	}
  	}
}			