×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    J2ME threading help

    i need help =(

    the problem i have is regarding the threading that i've used, in a form. i use a CustomItem class and input the threading codes inside. everyone works fine, animation moved.

    but the problem is its too FAST!

    Code:
    class AliceThread extends Thread{
                
                public void run(){
                    while (true) {
                        try{
                            sleep(300);
                        }catch(InterruptedException ie)	{
                            ie.printStackTrace();
                        }
                        x -= 20;
                        if(x <= 0 - image.getWidth())
                            x = getWidth();
                    }
                }
            }
    this is my threading class in my CustomeItem class.
    i understand that the sleep() method is the speed, but whatever value i input, it always is very fast.
    is it something to do with the repaint or anything?

    thanks in advance ^^

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME threading help

    If "x" is used in the paint() method, then you will need to issue a repaint() after changing it, so that the component knows it must update its appearance.

    You also need some way to stop the Thread. "while(true)" is a bad idea. "while(running)" is better, where "running" is a boolean instance variable.

  3. #3
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    Re: J2ME threading help

    Hi graham =),
    the repaint is in there in my latest code.
    and im using a canvas, not a midlet.
    that's why im using a customeItem class, because it allows me to use threading in a canvas, together with form.

    Thanks ^^

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: J2ME threading help

    Hi,
    Can you put the thread code here,
    Thanks,
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Nov 2008
    Posts
    31

    Re: J2ME threading help

    you mean the thread class? its in my first post =D

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: J2ME threading help

    Hmmmm... one thing that looks odd... is the two calls to getWidth() appear to be on different objects/classes.

    Could probably do with seeing some more of the code. Is it possible, for example, that more than one thread is being created?

Similar Threads

  1. J2ME or C++ for VoIP on Mobile
    By sandeepkumar03 in forum VoIP
    Replies: 4
    Last Post: 2009-02-02, 10:28
  2. threading image to a gif image ? (j2me)
    By intheworldofmyown in forum Mobile Java General
    Replies: 3
    Last Post: 2008-11-18, 17:31
  3. J2ME or C++ for VoIP on Mobile Phone
    By sandeepkumar03 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2008-11-13, 20:14
  4. How can the WAP browser communicate to J2ME application?
    By hbfornies in forum Mobile Java General
    Replies: 20
    Last Post: 2007-03-02, 16:32
  5. J2ME Polish Version 1.0 RC6
    By enough in forum Mobile Java General
    Replies: 1
    Last Post: 2004-07-20, 11:25

Posting Permissions

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