Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

J2ME can I use a Timer to execute a action every few seconds??

Posted on 2010-01-07
3
Medium Priority
?
834 Views
Last Modified: 2013-11-24
Hello guyz...

I am a bit stuck on my J2ME application atm what it does is it uses

mForm.addCommand(new Command("Find", Command.ITEM, 0));



     public void commandAction(Command c, Displayable d) {
        // Place your code here.
             if (c.getCommandType() == Command.EXIT)
                  notifyDestroyed();
            if (c.getCommandType() == Command.BACK)
                  mDisplay.setCurrent(mForm);
            if (c.getCommandType() == Command.ITEM && c.getLabel().equals("Find") )
            {
                  if( mForm.size() == 2 ) mForm.delete(1);
                  ListGetter lg = new ListGetter(this);
                  lg.start();
                  
            }
      }

As you can see everytime the Find button is pressed it goes to ListGetter(this is another java file that does a few things like appends the form with retrieved data from xml.

right what I was looking for was... is there anyways to have this executed with a timer instead of a command/button like say every 5 seconds?

                  if( mForm.size() == 2 ) mForm.delete(1);
                  ListGetter lg = new ListGetter(this);
                  lg.start();

Thank You.


Also could you tell me if I can position the text exactly where I want.. for example.. when i do mform.append(poi.name); can I place these anywhere on the screen using coordinates?? Thank You.
0
Comment
Question by:WarAngelos
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
arevuri earned 2000 total points
ID: 26199103
1) Timers:
You can use Timer and TimerTask APIs to run your logic on periodic basis. you can find these API in util package of J2ME
a) create a class that extends TimerTask and write your logic or call your method where your logic reside in run method (public void run()
b) Create Timer object and pass frequence value along with object of your class created in step a)
2) I think you can use Graphics API to place the text on the scree. I did not check this....just an ideal.
0
 

Author Comment

by:WarAngelos
ID: 26201389
Well I guess this the only way to do it.. I knew about this one.. but it wasn't working as you can see.. when it does lg.start() it goes to another Java Page.. so I think its actually leaving the timer.. mmm.. am thinking of ways to do it now.. thank you anyways.. ill award you the points but thanks
0
 

Author Closing Comment

by:WarAngelos
ID: 31673924
Well I guess this the only way to do it.. I knew about this one.. but it wasn't working as you can see.. when it does lg.start() it goes to another Java Page.. so I think its actually leaving the timer.. mmm.. am thinking of ways to do it now.. thank you anyways.. ill award you the points but thanks
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question