Results 1 to 8 of 8

Thread: show watch

  1. #1
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default show watch

    Hi i use this code to show watch but it`s not work please help me to modify it
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */

    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.*;

    /**
    * @author Mahdi Farzami
    */
    public class Samand extends MIDlet {

    Display display;
    Form form = new Form(" Samand ");

    String watch;
    Calendar calendar;
    Timer timer = new Timer();
    TimerTask timerTask = new TimerTask() {

    public void run() {

    watch();
    }
    };

    public void startApp() {

    display = Display.getDisplay(this);
    timer.schedule(timerTask, 100, 100);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void watch() {


    calendar = Calendar.getInstance();
    form.delete(1);

    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    watch = " " + hour + " : " + minute + " : " + second + "\n";

    form.append(watch);
    display.setCurrent(form);


    }
    }

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    10

    Default

    Don't just say "it's not work".
    Explain what is happening vs what you wanted to happen.
    No need to make people guess.

  3. #3
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    Hi it`s show Nothing to display , i want to show current time and it`s refresh each second

  4. #4
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    please help me how can i show watch in a form ???

  5. #5
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    286
    Rep Power
    9

    Default

    Java Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.util.*;
    
    /**
    * @author Mahdi Farzami
    */
    public class Samand extends MIDlet {
    
    Display display;
    Form form = new Form(" Samand ");
    StringItem si=new StringItem("Time","");
    String watch;
    Calendar calendar;
    Timer timer = new Timer();
    TimerTask timerTask = new TimerTask() {
    
    public void run() {
    
    watch();
    }
    };
    
    public void startApp() {
    form=new Form("Watch");
    form.append(si);
    display = Display.getDisplay(this);
    display.setCurrent(form);
    timer.schedule(timerTask, 0, 1000);
    }
    
    public void pauseApp() {
    }
    
    public void destroyApp(boolean unconditional) {
    }
    
    public void watch() {
    
    
    calendar = Calendar.getInstance();
    
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    watch = " " + hour + " : " + minute + " : " + second + "\n";
    si.setText(watch);
    }
    }

  6. #6
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    tanks my friend

  7. #7
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    Hi , how can i show clock in canvas ??? i can`t use Timer & TimerTask in canvas !!!

  8. #8
    mahdi-farzami is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    Hi , i use this code , it`s show time whene running midlet but it`s not change seconde or minute or hour after some time !!!
    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    import javax.microedition.lcdui.*;
    import java.util.*;
    
    /**
     * @author mahdi
     */
    public class WatchCanvas extends Canvas implements Runnable {
    
    
        private static final int SECOND = 1000;
        private static final int MINUTE = 60 * SECOND;
        private volatile boolean running;
    
        /**
         * constructor
         */
        public WatchCanvas() {
            try {
                setFullScreenMode(true);
                running = true;
                (new Thread(this)).start();
            } catch(Exception e) {
                e.printStackTrace();
            }
        }
        public void stop() {
            running = false;
        } 
        
        /**
         * paint
         */
        public void paint(Graphics g) {
            g.setColor(211,211,211);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(0);
            g.drawString(String.valueOf(Calendar.getInstance().getTime()), 100, 100, Graphics.HCENTER | Graphics.TOP);
        }
    
        public void run() {
            while (running) {
                try {
                    Thread.sleep(MINUTE);
                } catch (InterruptedException ie) {
                    // ignore
                }
                repaint();
            } 
        }
        
    
    
    }

Similar Threads

  1. watch expression in debug mode
    By bizso in forum Eclipse
    Replies: 6
    Last Post: 07-08-2009, 08:07 AM
  2. Watch TV on PC - 12,000 TV Channels and Movies, save money Get $10 rebate.
    By arturmoniswork in forum Reviews / Advertising
    Replies: 0
    Last Post: 12-30-2008, 06:56 AM
  3. [SOLVED] Folder watch Issue
    By jazz2k8 in forum New To Java
    Replies: 13
    Last Post: 07-24-2008, 05:46 AM
  4. netbeans 6.0 not show commpunent or show blank page
    By fahimaamir in forum NetBeans
    Replies: 1
    Last Post: 01-26-2008, 07:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •