×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    2

    progress bar, threads, network and problems

    Hi,

    I'm struggling for more than two days on a problem.

    I don't know well Java. I'm using since 4-5 months. That's probably the reason . If somebody out there could show me the right way. His/her help will be greeaaatttllyyyy appreciated :-).

    I've made a progress bar to indicate the HTTP request progression. It works. I t uses a thread to handle The HTTP connection. This connection is perfectly monitored by a gauge with gauge.setValue(X) all the way.


    the progress bar and the httpconnection are in the same class:
    ProgressBar.class

    It is not the MIDP main class.

    In the main class the code looks like:

    public void send_method() {

    // 1. Runnable implemented class with a thread to handle the connection.

    ProgressBar progressbar= new ProgressBar();

    // 2. method to launch the thread.

    progressbar.start();

    // 3. so far so good. I see the gauge. d is // the display.

    d.setCurrent(progressbar.form.gauge);

    // 4. but ...Here Once the connection is done...How can I detect it?

    }

    My problem is on the point 4. When the connection is done (success, IOException). I would like to redirect automatically the user to another method.

    How is it possible?
    If i call the method directly without any while/ if statement (ex: using a boolean variable into progressbar.class which is set true once the connection is done) Display doesn't work.


    public void send_method() {

    // 1. Runnable implemented class with a thread to handle the connection.
    ProgressBar progressbar= new ProgressBar();

    // 2. method to launch the thread.
    progressbar.start();

    // 3. so far so good. I see the gauge. d is // the display.
    d.setCurrent(progressbar.form.gauge);

    // 4. It doesn't work.
    while (!progressbar.booleanvariable) {
    }
    nextmethod();
    }

    I'm sure there is the "right way" to do it. But I cannot find it.

    Thanks so much for your help.

    Olivier

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    Set up callback methods, and have the thread that performs the connection call them when it's done:
    Code:
    void connectionComplete(boolean succeeded) {
      // whatever you want to do when the connection finishes
    }
    
    // the thread that run's the connection would look like this:
    try {
      connect();
      connectionComplete(true);
    }
    catch (Exception e) {
      connectionComplete(false);
    }
    shmoove

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    2
    Thank you for your answer. I've discovered how useful an interface can be ;-)

    Olivier

Posting Permissions

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