×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    12

    Problem on Delay painting

    I have the following code written. To paint the first graphic, stop a while and paint another graphic and then set display to another graphics object. But it seems not working property.

    .
    .
    .
    gc.drawImage(image1.....);
    repaint();
    start_time = System.currentTimeMillis();
    end_time = start_time;
    while(end_time<start_time+2000)
    {
    end_time = System.currentTimeMillis();
    }
    gc.drawImage(image2...);
    repaint();
    .
    .
    then set the display to another graphic objects

    gc is a buffer.
    the problem now is it do stop for a while when the loop run but it is not preforming the repaint() commands.
    Anyone got an idea to fix it ?
    I can't use thread in this class to preform this bcs i have the run() to perform another loop. THX

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280
    You need to do it in a separate thread, or use a Timer and a TimerTask, because otherwise you block the thread that's in charge of repainting the screen.

    If you already have a run() method in your class, you can use another class, or an inner class:
    Code:
    Thread t = new Thread() {
      public void run() {
        // do something
      }
    };
    t.start();
    You might also want to look into using Thread.sleep() instead of that loop for the delay.

    shmoove

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    12
    WOW.
    It works just as what i want.
    Thx a lot SUPERMAN

Posting Permissions

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