Calculator Application > Java ME
Calculator Application > Java ME Program
Mobile Communication and Computing
Program: import javax.microedition.lcdui.*;import javax.microedition.midlet.*;
public class Midlet extends MIDlet implements CommandListener {
Display d;
Ticker t;
Form f;
TextField tf1;
TextField tf2;
StringItem s1;
Command add,sub,div,mul;
public void startApp() {
d = Display.getDisplay(this);
f= new Form("Calculator");
d.setCurrent(f);
tf1 = new TextField("No:1","",10,TextField.NUMERIC);
f.append(tf1);
tf2 = new TextField("No:2","",10,TextField.NUMERIC);
f.append(tf2);
s1 = new StringItem("Result :","");
f.append(s1);
add=new Command("add",Command.SCREEN,0);
sub=new Command("sub",Command.SCREEN,0);
div=new Command("div",Command.SCREEN,0);
mul=new Command("mul",Command.SCREEN,0);
f.addCommand(add);
f.addCommand(sub);
f.addCommand(div);
f.addCommand(mul);
f.setCommandListener(this);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(c==add)
{
int a=Integer.parseInt(tf1.getString());
int b=Integer.parseInt(tf2.getString());
int s=a+b;
String t=s+"";
s1.setText(t);
}
if(c==sub)
{
int a=Integer.parseInt(tf1.getString());
int b=Integer.parseInt(tf2.getString());
int s=a-b;
String t=s+"";
s1.setText(t);
} if(c==div)
{
int a=Integer.parseInt(tf1.getString());
int b=Integer.parseInt(tf2.getString());
int s=a/b;
String t=s+"";
s1.setText(t);
} if(c==mul)
{
int a=Integer.parseInt(tf1.getString());
int b=Integer.parseInt(tf2.getString());
int s=a*b;
String t=s+"";
s1.setText(t);
}
}
}
OUTPUT:
Comments
Post a Comment