Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6953719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:30:55+00:00 2026-05-27T14:30:55+00:00

I make and display an clock count down with this code LabelField time; long

  • 0

I make and display an clock count down with this code

LabelField time;
            long mille=0;
            Timer timer=null;TimerTask task=null;
            public Timerscreen() {
                mille=1000*60*1;
                time=new LabelField();
                add(time);
                timer=new Timer();

                task=new TimerTask() {

                    public void run() {
                        synchronized (UiApplication.getEventLock()) {

                            if(mille!=0){
                                SimpleDateFormat date=new SimpleDateFormat("mm:ss") ;
                                System.out.println("================="+date.formatLocal(mille)+"====================="+Thread.activeCount());
                                time.setText(date.formatLocal(mille));
                                mille=mille-1000;
                            }else{
time.setText("00:00");
mille=1000*60*1;
                                timer.cancel();
                                UiApplication.getUiApplication().invokeLater(new Runnable() {
                                    public void run() {
                                        Dialog.inform("Time expaired");
                                    }
                                });

                            }
                        }
                    }
                };
                timer.schedule(task,0, 1000);

And when I push a new screen , I want to this clock still display and count down.
How can I do that ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:30:56+00:00Added an answer on May 27, 2026 at 2:30 pm

    It is not possible to add a single ui field or manager into two managers or screens.. every ui field or manager must have at most one parent (screen or manager).

    So if you need a LabelField which will hold and show time on different screens, then you only need to implement some sort of listener which will listen for the time changes.. and for every changes you have to update the screen and the LabelField with the new value. You have already implemented a TimerTask which will provide you updated data.

    [Edited – added later]

    you can check the following codes, not tested but something like this will solve your problem…

    class MyTimerUtil {
        TimerListener listener = null;
    
        public MyTimerUtil() {      
        }
    
        public void setTimerListener(TimerListener listener) {
            this.listener = listener;
        }
    
        public void startTimer() {
            final int interval = 1000;
            Timer timer = new Timer();
            TimerTask task = new TimerTask() {
                public void run() {
                    // add your codes..
    
                    // notify others
                    if (listener != null) {
                        listener.timeChanged();
                    }
                }
            };
            timer.schedule(task, 0, interval);
        }
    }
    
    
    interface TimerListener {
        public void timeChanged();
    }
    
    class ScreeA extends MainScreen implements TimerListener {
    
        public void timeChanged() {
            // add Codes here on time changed event     
        }   
    }
    

    in the above snippet, you can implement TimerListener interface in any screen instance and can get update on every time changed event by the MyTimerUtil class. For that, you have to set an instance of ScreeA (which implements TimerListener) via setTimerListener() of the MyTimerUtil class.

    Also need to start the timer by calling startTimer() method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given this HTML: <div>foo</div><div>bar</div><div>baz</div> How do you make them display inline like this: foo
I'm utilizing the code posted by Jesper Palm here: Make user control display outside
I am trying to make the image title display at the same time the
How do you make a Countdown timer? When the user loads the page, clock
This code will display the selected value from the listbox. E.g. if I sellect
I am learning GDI+ and I am trying to make a display window with
Is there a way to add styling to rails form_for and make it display
The following div's are displayed onclick. How can I make it display a different
Suppose I have an element called #container-main . How do I make that display:none
I can make Firefox not display the ugly dotted focus outlines on links with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.