import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class tambah extends MIDlet implements CommandListener {
private Display dd;
private Form fi;
private Command tambah,cmdkeluar, kurang,kali,bagi;
private TextField n1,n2,n3;
public tambah(){
cmdkeluar = new Command("Keluar", Command.EXIT,1);
kurang = new Command("-", Command.OK,1);
tambah = new Command("+", Command.OK,1);
kali = new Command ("x", Command.OK,1);
bagi = new Command ("/", Command.OK,1);
n1 = new TextField("Nilai 1 : ",null,10,0);
n2 = new TextField("Nilai 2 : ",null,10,0);
n3 = new TextField("Hasil : ",null,13,0);
fi=new Form("Penjumlahan");
fi.addCommand(cmdkeluar);
fi.addCommand(tambah);
fi.addCommand(kurang);
fi.addCommand(kali);
fi.addCommand(bagi);
fi.append(n1);
fi.append(n2);
fi.append(n3);
fi.setCommandListener(this);
}
public void startApp() {
dd = Display.getDisplay(this);
dd.setCurrent(fi);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(d==fi){
if (c==cmdkeluar){
destroyApp(false);
notifyDestroyed();
}
else if (c==tambah){
int d1,d2,d3;
d1= Integer.parseInt(n1.getString());
d2= Integer.parseInt(n2.getString());
d3=d2+d1;
n3.setString(String.valueOf(d3));
}
else if (c==kurang){
int d1,d2,d3;
d1= Integer.parseInt(n1.getString());
d2= Integer.parseInt(n2.getString());
d3=d1-d2;
n3.setString(String.valueOf(d3));
}
else if (c==kali){
int d1,d2,d3;
d1= Integer.parseInt(n1.getString());
d2= Integer.parseInt(n2.getString());
d3=d1*d2;
n3.setString(String.valueOf(d3));
}
else if (c==bagi){
int d1,d2,d3;
d1= Integer.parseInt(n1.getString());
d2= Integer.parseInt(n2.getString());
d3=d1/d2;
n3.setString(String.valueOf(d3));
}
}
}
}
0 komentar:
Posting Komentar