/* * mobclock.java * * Created on November 26, 2007, 10:28 PM */ package clock; import javax.microedition.midlet.*; import javax.microedition.lcdui.*; import java.util.*; /** * * @author sjuva */ public class mobclock extends MIDlet implements CommandListener { /** Creates a new instance of mobclock */ public mobclock() { initialize(); } private Form form1;//GEN-BEGIN:MVDFields private Command exitCommand1; private DateField dateField1; private Spacer spacer1;//GEN-END:MVDFields private aclock aC; private Timer timer; //GEN-LINE:MVDMethods /** Called by the system to indicate that a command has been invoked on a particular displayable.//GEN-BEGIN:MVDCABegin * @param command the Command that ws invoked * @param displayable the Displayable on which the command was invoked */ public void commandAction(Command command, Displayable displayable) {//GEN-END:MVDCABegin // Insert global pre-action code here if (displayable == form1) {//GEN-BEGIN:MVDCABody if (command == exitCommand1) {//GEN-END:MVDCABody // Insert pre-action code here // Do nothing//GEN-LINE:MVDCAAction4 // Insert post-action code here exitMIDlet(); }//GEN-BEGIN:MVDCACase4 }//GEN-END:MVDCACase4 // Insert global post-action code here }//GEN-LINE:MVDCAEnd /** This method initializes UI of the application.//GEN-BEGIN:MVDInitBegin */ private void initialize() {//GEN-END:MVDInitBegin // Insert pre-init code here exitCommand1 = new Command("Exit", Command.EXIT, 1);//GEN-BEGIN:MVDInitInit spacer1 = new Spacer(1000, 10); dateField1 = new DateField("", DateField.DATE_TIME); dateField1.setLayout(Item.LAYOUT_CENTER); form1 = new Form(null, new Item[] { dateField1, spacer1 }); form1.addCommand(exitCommand1); form1.setCommandListener(this);//GEN-END:MVDInitInit // Insert post-init code here aC = new aclock(null, 100); aC.setLayout(Item.LAYOUT_CENTER); form1.append(aC); }//GEN-LINE:MVDInitEnd /** * This method should return an instance of the display. */ public Display getDisplay() {//GEN-FIRST:MVDGetDisplay return Display.getDisplay(this); }//GEN-LAST:MVDGetDisplay /** * This method should exit the midlet. */ public void exitMIDlet() {//GEN-FIRST:MVDExitMidlet getDisplay().setCurrent(null); destroyApp(true); notifyDestroyed(); }//GEN-LAST:MVDExitMidlet public void startApp() { getDisplay().setCurrent(form1); timer = new Timer(); TimerTask ttask = new TimerTask() { public void run() { update(); } } ; timer.scheduleAtFixedRate(ttask, 1, 1000); } private void update() { dateField1.setDate(new Date()); aC.update(); } public void pauseApp() { if (timer != null) { timer.cancel(); timer = null; } } public void destroyApp(boolean unconditional) { } }