/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package hello;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.*;
/**
* @author pika
*/
public class latihanPertamax extends MIDlet implements CommandListener{
Display disp;
Form fi, fh;
StringItem lblC, lblF, lblR,lblHF, lblHC, lblHR;
TextField txtC, txtF, txtR;
Command cmdKeluar, cmdHitung, cmdKembali;
int cl, re, fr, hf, hr, hc;
public latihanPertamax()
{
fi = new Form("Masukkan Satuan Suhu");
lblC = new StringItem("","Celcius", StringItem.PLAIN);
txtC = new TextField("", "", 30, TextField.NUMERIC);
lblF = new StringItem("","Fahrenheit", StringItem.PLAIN);
txtF = new TextField("", "", 30, TextField.NUMERIC);
lblR = new StringItem("","Reamur", StringItem.PLAIN);
txtR = new TextField("", "", 30, TextField.NUMERIC);
cmdKeluar = new Command("Keluar", Command.EXIT, 0);
cmdHitung = new Command("Hitung", Command.OK, 0);
fi.append(lblC);
fi.append(txtC);
fi.append(lblF);
fi.append(txtF);
fi.append(lblR);
fi.append(txtR);
fi.addCommand(cmdKeluar);
fi.addCommand(cmdHitung);
fi.setCommandListener(this);
}
public void startApp() {
disp = Display.getDisplay(this);
disp.setCurrent(fi);
}
public void hitungSuhu()
{
fh = new Form("Hasilnya");
Hitung h = new Hitung();
if(!txtC.getString().equals(""))
{
cl = Integer.parseInt(txtC.getString());
hf = h.hitCF(cl);
hr = h.hitCR(cl);
lblHF = new StringItem("", "", StringItem.PLAIN);
lblHF.setText("Hasil (Fahrenheit)= " + hf);
lblHR = new StringItem("", "", StringItem.PLAIN);
lblHR.setText("\nHasil (Reamur)= " + hr);
fh.append(lblHF);
fh.append(lblHR);
}
else if(!txtF.getString().equals(""))
{
fr = Integer.parseInt(txtF.getString());
hc = h.hitFC(fr);
hr = h.hitFR(fr);
lblHC = new StringItem("", "", StringItem.PLAIN);
lblHC.setText("Hasil (Celcius)= " + hc);
lblHR = new StringItem("", "", StringItem.PLAIN);
lblHR.setText("\nHasil (Reamur)= " + hr);
fh.append(lblHC);
fh.append(lblHR);
}
else
{
re = Integer.parseInt(txtR.getString());
hc = h.hitRC(re);
hf = h.hitRF(re);
lblHC = new StringItem("", "", StringItem.PLAIN);
lblHC.setText("Hasil (Celcius)= " + hc);
lblHF = new StringItem("", "", StringItem.PLAIN);
lblHF.setText("\nHasil (Fahrenheit)= " + hf);
fh.append(lblHC);
fh.append(lblHF);
}
cmdKembali = new Command("Kembali", Command.BACK, 0);
fh.addCommand(cmdKembali);
fh.setCommandListener(this);
disp.setCurrent(fh);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable d) {
if(d == fi)
{
if(c == cmdHitung)
{
hitungSuhu();
}
else if(c == cmdKeluar)
{
destroyApp(true);
notifyDestroyed();
}
}
else
{
if(c == cmdKembali)
{
disp.setCurrent(fi);
txtC.setString(null);
txtF.setString(null);
txtR.setString(null);
}
}
}
}
rincian script selengkapnya + program jadi unduh di sini
credit : audition emoticon on candrabeqx.net