/* Arithmetc Test*/
import java.lang.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
public class ArithTest extends MIDlet implements CommandListener{
private Display d;
private Form f;
private Command ce,c1,c2,c3,c4;
private TextField num1,num2,res;
public void startApp(){
d = Display.getDisplay(this);
f = new Form("Test");
num1 = new TextField("N1","",6,TextField.NUMERIC);
num2 = new TextField("N2","",6,TextField.NUMERIC);
res = new TextField("R1","",6,TextField.NUMERIC|TextField.UNEDITABLE);
ce = new Command("EXIT",Command.EXIT,1);
c1 = new Command("ADD",Command.ITEM,1);
c2 = new Command("SUB",Command.ITEM,1);
c3 = new Command("MUL",Command.ITEM,1);
c4 = new Command("DIV",Command.ITEM,1);
f.append("Helllo how
are you");
f.append(num1);
f.append(num2);
f.append(res);
f.addCommand(c4);
f.addCommand(c1);
f.addCommand(c2);
f.addCommand(c3);
f.addCommand(ce);
f.setCommandListener(this);
d.setCurrent(f);
}
public void pauseApp(){}
public void destroyApp(boolean
unconditional){}
public void commandAction(Command
c,Displayable s){
int
n1,n2,r1;
if(
c == ce)
notifyDestroyed();
else if(c == c1){
n1 = Integer.parseInt(num1.getString());
n2 = Integer.parseInt(num2.getString());
r1 = n1+n2;
res.setString(""+r1);
}
else if(c == c2){
n1 = Integer.parseInt(num1.getString());
n2 = Integer.parseInt(num2.getString());
r1 = n1-n2;
res.setString(""+r1);
}
else if(c == c3){
n1 = Integer.parseInt(num1.getString());
n2 = Integer.parseInt(num2.getString());
r1 = n1*n2;
res.setString(""+r1);
}
else if (c == c4){
n1 = Integer.parseInt(num1.getString());
n2 = Integer.parseInt(num2.getString());
r1 = n1/n2;
res.setString(""+r1);
}
}
}