Search code examples
javasearchsliding-tile-puzzle

Search algorithms (DFS,BFS,A star etc.). How to update the GUI (with updated state) without "freezing"?


My question is rather simple.

Let's suppose I'm executing the algorithm "A star" (search algorithm using a heuristic function to calculate next state to visit).

I want to show in a grid the updates (I will apply it to 8-puzzle problem). How should I do that? I want changes to be clearly visible.. but in my experience if I just do something like Grid[6].showValue(newValue) the GUI will just "stand-by".

I'm sure this could be done with multi-threading (maybe?) but is there any simpler way?

And one more very easy question if possible: I wonder if in Java (my IDE is Netbeans) there is any class containing methods for searching like BFS, DFS and A star? If so, could you provide a link to the code of the algorithms (I need to use them as a base for my code.. I can't include them directly.. you know.. university assignment). I suppose this code is easy to find since Java is a open-source language. Am I wrong?

Thank you very much


Solution

  • Don't do the processing in the GUI thread.

    If we're talking about here, that's the Event Dispatch Thread; use worker threads as described in the Concurrency in Swing tutorial.