repaint() call doesn't get processed

Discussion in 'Java' started by Esko Piirainen, Nov 12, 2005.

  1. I'm doing a graphical interface to test different path finding algorithms.

    Here is just a small test "algorithm" that I'm using to build up the
    graphical methods I need. It starts from the start point and just moves
    straight to the right until it reaches the end of the area (int[][]
    squares).
    I want to separate the path finding algorithms from counting different stuff
    and drawing the graphics and that is why examineSquare() method is being
    used.


    Part of code from "path finder" :
    ......
    while (contents != FINISH)
    {
    if (x < maxX)
    contents = examineSquare(x+1,y); // problems are with method used
    here
    else
    {
    noRoute();
    break;
    }
    }
    //route found
    ......


    Here is the examineSquare() method that causes problems:

    private synchronized int examineSquare(int newX, int newY)
    {

    // Do some stuff with counters and manipulate the other
    // variables that canvas uses with paint()

    myCanvas.repaint();

    // then I want the program to take a little break
    try { wait ( theLenghtofDelay[speed] ); }
    catch (Exception e) { System.out.println(e.toString()); }

    x = newX;
    y = newY;

    return squares[x][y];
    }

    For some reason the program never executes the paint() method. Why?
    Screen gets repainted only after the while loop has ended.

    Same repaint() is used in many different parts of my program without
    problems.
    Esko Piirainen, Nov 12, 2005
    #1
    1. Advertising

  2. Esko Piirainen

    Guest

    I'm not an expert on this but it seems that your wait() statement
    executes on the same thread as the graphics update thread. The
    repaint() method just places an "update" request on the main event
    thread. Are you using Swing or AWT? Have you tried using
    SwingUtilities.invokeLater() method? I think, what basically should
    happen is, you should separate the main event thread and your
    examinSquare() method executing thread, to allow the GUI to update
    itself while your wait() is executing.

    Hope this helps,
    -murat
    , Nov 12, 2005
    #2
    1. Advertising

  3. Yes, perfectly clear now. I placed it to different thread and it's working.

    Thanks!


    <> wrote in message
    news:...
    > I'm not an expert on this but it seems that your wait() statement
    > executes on the same thread as the graphics update thread. The
    > repaint() method just places an "update" request on the main event
    > thread. Are you using Swing or AWT? Have you tried using
    > SwingUtilities.invokeLater() method? I think, what basically should
    > happen is, you should separate the main event thread and your
    > examinSquare() method executing thread, to allow the GUI to update
    > itself while your wait() is executing.
    >
    > Hope this helps,
    > -murat
    >
    Esko Piirainen, Nov 12, 2005
    #3
  4. Esko Piirainen

    Roedy Green Guest

    On Sat, 12 Nov 2005 18:09:45 +0200, "Esko Piirainen"
    <> wrote, quoted or indirectly quoted
    someone who said :

    > try { wait ( theLenghtofDelay[speed] ); }


    it is impossible to paint while asleep.

    See http://mindprod.com/jgloss/swingthreads.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Nov 13, 2005
    #4
  5. wrote:
    > I'm not an expert on this but it seems that your wait() statement
    > executes on the same thread as the graphics update thread. The
    > repaint() method just places an "update" request on the main event
    > thread. Are you using Swing or AWT? Have you tried using
    > SwingUtilities.invokeLater() method? I think, what basically should
    > happen is, you should separate the main event thread and your
    > examinSquare() method executing thread, to allow the GUI to update
    > itself while your wait() is executing.


    Rather than just trying invokeLater randomly, it's better to have a very
    clear idea what your threads are doing. You can indicate to the reader
    whether you expect to be in the AWT Event Dispatch Thread (EDT) or not,
    using assert EventQueue.isDispatchThread(); or assert
    !EventQueue.isDispatchThread();. If you remember to use -ea or
    -enableassertions, then the runtime will check your assertion for you. A
    similar thing goes for Thread.holdsLock.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
    Thomas Hawtin, Nov 14, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. stan k.
    Replies:
    1
    Views:
    9,724
    Babu Kalakrishnan
    Nov 7, 2003
  2. Yoshi
    Replies:
    5
    Views:
    868
    Yoshi
    Mar 4, 2004
  3. Z
    Replies:
    12
    Views:
    4,946
    Knute Johnson
    Feb 19, 2007
  4. Kgbol
    Replies:
    4
    Views:
    1,121
  5. Palan

    aspx not processed on GET only POST

    Palan, Apr 21, 2008, in forum: ASP General
    Replies:
    2
    Views:
    126
    Palan
    Apr 21, 2008
Loading...

Share This Page