StopWatch sederhana untuk Handphone dengan J2ME
Minggu, April 20, 2008 22:24Posted in category Komputer, Pemrograman
Tadi malem belajar menggunakan Timer di J2ME. Iseng iseng untuk percobaan pertama aku buat aplikasi StopWatch untuk Handphone. Mudah mudahan aja coding nya bener. kalo ada yang gak bener ato salah semua mohon ralatnya ya. Oya ga ada screenShotnya. padahal tadi udah tak bikin. tapi lupa gak kebawa. masih di komputer rumah.
Ini contoh code nya:
/**
*
* @author MasWawa
*/
import java.util.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class StopWatch extends MIDlet implements CommandListener{
private Display display;
private Form fmMain;
private TextField text;
private Command cmExit;
private Command cmStart;
private Command cmStop;
private Timer tm;
private TimerTask tt;
private int count,count1,count2,count3;
public StopWatch(){
display = Display.getDisplay(this);
text = new TextField(null, " 00 : 00 : 00 : 0", 25, TextField.ANY);
nolkan();
fmMain = new Form("Stopwatch Ku");
fmMain.append("Start untuk Memulai dan Stop untuk berhenti");
fmMain.append(text);
cmExit = new Command("Exit", Command.EXIT, 1);
cmStart = new Command("Start",Command.OK,2);
cmStop= new Command("Stop", Command.STOP, 3);
addComm(1);
}
private void nolkan(){
count=0;
count1=0;
count2=0;
count3=0;
}
private void start(){
nolkan();
tm = new Timer();
tt = new TimerRun();
tm.schedule(tt,0,100);
}
private void addComm(int code){
if (code == 1){
fmMain.addCommand(cmStart);
}else if(code == 2){
fmMain.addCommand(cmStop);
}
fmMain.addCommand(cmExit);
fmMain.setCommandListener(this);
}
public void startApp (){
display.setCurrent(fmMain);
}
public void destroyApp (boolean unconditional){
notifyDestroyed();
}
public void pauseApp (){
}
public void commandAction(Command c, Displayable d){
if (c == cmStart){
fmMain.removeCommand(c);
addComm(2);
start();
} else if (c == cmStop){
fmMain.removeCommand(c);
addComm(1);
tm.cancel();
}else if (c == cmExit){
destroyApp(true);
}
}
private class TimerRun extends TimerTask{
public final void run(){
if(++count > 9){
count=0;
++count1;
}
if(count1 > 59){
count1=0;
++count2;
}
if(count2 > 59){
count2=0;
++count3;
}
if (count3 > 23){
nolkan();
}
text.setString(" " + count3 + " : "+ count2 +
" : " + count1 + " : " + count);
}
}
}
Related posts:
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.








taka_666 says:
November 4th, 2008 at 01:43
permisi mas…
mau tanya mas…boleh kan..coz udah bingung banget..
kalo j2me kalo kita pake file .txt bisa gak kita tambah data???
contoh codingnya gimana mas…
hehe..makasih ya mas sebelumnya…
leniah says:
April 10th, 2009 at 23:33
mas mau tanya juga nh….gmn codingnya lho pke fasilitas PAUSE???
makasih sebelum….ditunggu bantuannya…
leniah says:
April 10th, 2009 at 23:36
maaf ada yg ketinggalan mas…
gmn mas codingnya lho buat aplikasi jam dan tanggal tapi pke class canvas di j2me…???
mohon bantuannya..makasih…
pameliakoj says:
Januari 2nd, 2010 at 14:47
It is a pity, that now I can not express – I am late for a meeting. I will be released – I will necessarily express the opinion. cialias com Michigan Wanna very nice joke?)) Did you hear about the butcher who accidentally backed into the meat grinder? He got a little behind in his work.