Using two buttons market timer / stop, need help please.

Hey everybody.

I am stil working on my project, and now I'm trying to implement a timer using two buttons market / stop. Everything I do now is when you press start the stopwatch starts and when you press stop I want the timer to stop and display the time.

Whats happening is when I press start, the timer starts, but when stop is pressed the timer displays a value of say 12 seconds, a second more later I press stop again a value of 14secs arise and it stops at 14.  Now, whenever I press on start it will start at 14 and repeat this process.

So I think that somewhere, I did not put my right timer.

Could someone say somethings that I should change in my code.

They are declared at the top:

static public boolean status=false;
static public int count=0;
static public Timer timer;

Here is my code:

ButtonField start = new ButtonField("Start",ButtonField.USE_ALL_WIDTH|                          ButtonField.FIELD_HCENTER|ButtonField.USE_ALL_HEIGHT);                          start.setChangeListener(new Listener1());add(start);

ButtonField stop = new ButtonField("Stop",ButtonField.USE_ALL_WIDTH|                            ButtonField.FIELD_HCENTER|ButtonField.USE_ALL_HEIGHT);                            stop.setChangeListener(new Listener2());                          add(stop);          

            public class Listener2 implements FieldChangeListener            {            public void fieldChanged(Field field, int context)             {            ButtonField btn = (ButtonField) field;            Status.show("Timer is at" + Integer.toString(count));            status = false;            timer.cancel();            }            }

            public class Listener1 implements FieldChangeListener            {            public void fieldChanged(Field field, int context)             {            ButtonField btn = (ButtonField) field;            Status.show("Timer started");            status = true;                try                {                                                timer = new Timer();                                        timer.scheduleAtFixedRate(new StartEvent(),1,1000);                }                catch(Exception e)                {                //do nothing                }            }

    private class StartEvent extends TimerTask    {    public void run()       {        if(status = true)              {              count++;                        }        else            timer.cancel();//        count=0;    }    }    }

any help is appreciated

Thank you guys

Probably best to follow just a matter of a Thread.  So next time, you can start a new Thread with a new question.  However, you should also search the forum before asking questions, that your two supplementary questions have been answered in other posts on this forum.

Concerning your problem to press the stop and get another moment, I think that you must have application logic that disables the stop button once pressed, until you press the Start button.  For example, you could do by assigning to the time of departure - 1 in the Stop button, and then, when you press the Stop button, he can check the start time and displays a message saying "Timer not started" If the start time is - 1.  There are a number of other ways to do this, I described this method because it is easy to explain.  It is not really how I'd do.

The best way to set the buttons next, is to add then to a HorizontalFieldManager, then add the HorizontalFieldManager to your screen.

To stop the button displays the menu, you must set it with the style CONSUME_CLICK, for example:

ButtonField stopButton = new ButtonField ("Stop", ButtonField.CONSUME_CLICK);

Tags: BlackBerry Developers

Similar Questions

Maybe you are looking for

  • MacBook Pro fan ap

    Have a 2008 17 MBP, now with 1 TB SSD. It heats up and I am deaf so need a fan ap to see his work. Last rev of El Capitan works well. What ap to get? Thank you! JIm in Chicago

  • Skype crashes on start up

    Name of the failing application: Skype.exe, version: 7.0.0.102, time stamp: 0x54897addName of the failed module: Skype.exe, version: 7.0.0.102, time stamp: 0x54897addException code: 0xc0000005Offset: 0x00d527d7ID of the process failed: 0 x 1744Start

  • Why a trail shaded in an album of my friends?

    Why a track appears dimmed in an album of my friends, and what that means? iTunes can play the track if you click on it, but if it comes after another track iTunes jump it! I have the latest version of iTunes.

  • Backup of the stolen device

    Hello I want to ask this; What happens if someone steals my iphone / backup file of the ipad to my itunes or something like that. What can do with my backup of the device? I can nothing detected when it is?

  • All three 5DrS crop factors performance 60 MB + trust

    It would seem reasonable that when you choose to create an image cropped on the 5Drs, the smaller stage should still fill the viewfinder to produce a good view of the subject.   It should also that a cropped image would result in a smaller file when