Home | J2ME Yours page | Favorite Links | Contact Me | objques | Canvas Demo | Fruit selection | Commands | Gauge NI | Gauge Response | Pallet | Pal Ex Mid | Slides Text
Prasad's J2ME programs
Favorite Links

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

public class TestMid extends MIDlet implements CommandListener,ItemStateListener{
private Display d;
private Ticker t;
private Form f,arithForm,arChForm;
private Command c,c1,c2,c3,cback,chback;
private ChoiceGroup cg,cg1,arpop,arRadio,arCheck;
private String[] cst;
private TextField first,second,res,firstCheck,secondCheck,resBox;

// private int firnum,secnum;
private float firnum,secnum,firnumCh,secnumCh;
private Timer t1;
private TestTimerTask task;
public TestMid(){
d =  Display.getDisplay(this);
f = new Form("Test");
arithForm = new Form ("Arithmetic  Operations");
arChForm = new Form ("Arithmetic  Check Operations");
t = new Ticker("This is 'MAD' Laboratory");

cst =new String[] {"09251A1266","09251A1267"};
cg1 = new ChoiceGroup("IT-B1",Choice.MULTIPLE,cst,null);
cg = new ChoiceGroup("IT-B",Choice.EXCLUSIVE);
arpop = new ChoiceGroup("ArithPop",Choice.POPUP,new String[]{"ADD","SUB","MUL","DIV"},null);
arRadio = new ChoiceGroup("ArithRadio",Choice.EXCLUSIVE,new String[]{"ADD","SUB","MUL","DIV"},null);
arCheck = new ChoiceGroup("ArithCheck",Choice.MULTIPLE,new String[]{"ADD","SUB","MUL","DIV"},null);


cg.append("09251A1266",null);
cg.append("09251A1267",null);
cg.append("09251A1268",null);
cg.append("09251A1269",null);

c = new Command("EXIT",Command.EXIT,1);
c1 = new Command("ARITHFORM",Command.ITEM,1);
c2 = new Command("ARCHFORM",Command.ITEM,1);
c3 = new Command("EXIT3",Command.ITEM,1);
cback = new Command("BACK",Command.BACK,1);
chback = new Command("CHBACK",Command.BACK,1);
/* first  = new TextField("ONE","",10,TextField.NUMERIC);
second = new TextField("TWO","",10,TextField.NUMERIC);
res    = new TextField("RES","",10,TextField.NUMERIC|TextField.UNEDITABLE);*/

firstCheck  = new TextField("ONE","",10,TextField.DECIMAL);
secondCheck = new TextField("TWO","",10,TextField.DECIMAL);
resBox    = new TextField("RES","",100,TextField.ANY|TextField.UNEDITABLE);


first  = new TextField("ONE","",10,TextField.DECIMAL);
second = new TextField("TWO","",10,TextField.DECIMAL);
res    = new TextField("RES","",10,TextField.DECIMAL|TextField.UNEDITABLE);
arithForm.append(first);
arithForm.append(second);
arithForm.append(res);
arithForm.append(arpop);
arithForm.append(arRadio);

arChForm.append(firstCheck);
arChForm.append(secondCheck);
arChForm.append(arCheck);//choice group 
arChForm.append(resBox);


f.append("Hell lo how are you");
f.append(cg);
f.append(cg1);


f.addCommand(c);
f.addCommand(c1);
f.addCommand(c2);
f.addCommand(c3);
arithForm.addCommand(cback);
arithForm.setCommandListener(this);
arithForm.setItemStateListener(this);
arithForm.setTicker(t);

f.setCommandListener(this);
f.setTicker(t);

arChForm.addCommand(chback);
arChForm.setCommandListener(this);
arChForm.setItemStateListener(this);
arChForm.setTicker(t);

}

public void startApp(){
d.setCurrent(f);
/*while(true){
d.setCurrent(f);
try{
Thread.sleep(10000);
}catch(Exception e){}
d.setCurrent(arithForm);
try{
Thread.sleep(10000);
}catch(Exception e){}
d.setCurrent(arChForm);
try{
Thread.sleep(10000);
}catch(Exception e){}
  }*/
}
public void pauseApp(){}

public void destroyApp(boolean unconditional){}

public void commandAction(Command c,Displayable s){
if(c.getCommandType() == Command.EXIT){
notifyDestroyed();}
else if(c == c1){
d.setCurrent(arithForm);
}
else if(c == cback){
d.setCurrent(f);
}
else if(c == c2){
d.setCurrent(arChForm);
}
else if(c == chback){
d.setCurrent(f);
}
}

public void itemStateChanged(Item it){
if (it == arpop)
arithProcess((ChoiceGroup)it);
else if(it == arRadio)
arithProcess((ChoiceGroup)it);
else if(it == arCheck)
arithCheckProcess((ChoiceGroup)it);

}

public void arithProcess(ChoiceGroup ch){
/* firnum = Integer.parseInt(first.getString());
secnum = Integer.parseInt(second.getString());*/

firnum = Float.parseFloat(first.getString());
secnum = Float.parseFloat(second.getString());

if( ch.getString(ch.getSelectedIndex()).equals("ADD") )
res.setString( ""+(firnum + secnum)); 
else if( ch.getString(ch.getSelectedIndex()).equals("SUB") )
res.setString( ""+(firnum - secnum));
else if( ch.getString(ch.getSelectedIndex()).equals("MUL") )
res.setString( ""+(firnum * secnum)); 
else if( ch.getString(ch.getSelectedIndex()).equals("DIV") )
res.setString( ""+(firnum / secnum));
}

public void arithCheckProcess(ChoiceGroup ch){
String restr;
boolean[] selfl;
firnumCh = Float.parseFloat(firstCheck.getString());
secnumCh = Float.parseFloat(secondCheck.getString());
selfl = new boolean[ch.size()];
ch.getSelectedFlags(selfl);
restr = "";
for(int i = 0;i<ch.size();i++){
if(selfl[i])
restr = restr +ch.getString(i)+" is "+AProcess(i)+"; ";
}
resBox.setString(restr);
}
public float AProcess(int i){
if(i == 0)
return (firnumCh+secnumCh);
else if(i == 1)
return (firnumCh-secnumCh);
else if(i == 2)
return (firnumCh*secnumCh);
else if(i == 3)
return (firnumCh/secnumCh);
return -1;

}


}

 class TestTimerTask extends TimerTask{
public void run(){
}
}

babu

Here's a link to the site of the company I work for:

www.trellix.com

Here's a link to a friend's site:

www.myfriend.com


"Striving for success without hard work is like trying to harvest where you haven't planted."