import java.awt.*;
public class valik extends Panel{
double min=0, alg=1, max=100;
TextField tf=new TextField(5);
double vaartus=1, vahe=1;
int komataga=2;
Button nv=new Button("<"), np=new Button(">");
String ise="";
abiapl ap;
public valik(abiapl at, String st){
 ap=at;
 ise=st;
 setLayout(new BorderLayout());
 add("West", nv);
 add("Center", tf);
 add("East", np);
 vaartus=alg;
 tf.setText(Double.toString(vaartus));
}
public valik(abiapl at, String st, double mv, double av, double sv, double vv){
 min=mv; alg=av; max=sv; vahe=vv;
 ap=at;
 ise=st;
 setLayout(new BorderLayout());
 add("West", nv);
 add("Center", tf);
 add("East", np);
 vaartus=alg;
 tf.setText(Double.toString(vaartus));
}

public boolean action(Event e, Object arg){
double abi;
 if(e.target==nv){abi=vaartus-vahe;if(abi>=min)vaartus-=vahe;}
 if(e.target==np){abi=vaartus+vahe;if(abi<=max)vaartus+=vahe;}
 if(e.target==tf){abi=Double.valueOf(tf.getText()).doubleValue();
                 if(!Double.isNaN(abi)&(abi>=min)&(abi<=max))vaartus=abi;}
 //tf.setText(Double.toString(vaartus));
tekst_korda(); 
ap.seaVaartus(this);
 return true;
}
public boolean keyUp(Event e, int key){
double abi;
 if(e.target==tf){abi=Double.valueOf(tf.getText()).doubleValue();
                 if(!Double.isNaN(abi)&(abi>=min)&(abi<=max))vaartus=abi;}
// tf.setText(Double.toString(vaartus));
tekst_korda();
 ap.seaVaartus(this);
 return true;
 
}

void tekst_korda(){
String s=Float.toString((float)vaartus);
if(komataga!=-100){
 int koht=s.indexOf(".");
 if(s.indexOf("E")>0)s="0";
 if(s.length()>koht+komataga)s=s.substring(0, koht+komataga+1);
 }
tf.setText(s);
}
}
