MДΓΓ БДLL が提案したように、別のスレッドで処理を行う必要があります。Runnable
基本的に、スレッド内で実行できるようにクラスを「マーク」するを実装するクラスに、検索関連のコードを実装する必要があります。
これを行うには、次を使用できますSwingWorker
。
SwingWorker<Integer[], Void> worker = new SwingWorker<Integer[], Void>() {
public Integer[] doInBackground() {
//do the computation here. This will be executed in a different thread;
//thus allowing the event dispatch thread (=GUI thread) to ensure responsiveness of the UI.
//NEVER update your GUI here since this could cause strange errors that are sometimes hard to track down.
}
public void done() {
try {
Integer[] result = get(); //this is executed in the GUI thread after
//execution if the doInBackground method finished and fetches the result of
//that method. You should update your GUI here.
} catch (InterruptedException ex) {
ex.printStackTrace();
} catch (ExecutionException ex) {
ex.printStackTrace();
}
}
}
2 番目の回答: 特に BFS、DFS、A-Star を使用しているツリーにはあらゆる種類のデータが含まれている可能性があるため、さまざまなデータ型に使用できるような一般的な方法でアルゴリズムを実装するのはかなり困難です。教科書または講義ノードの疑似コードでアルゴリズムを見つける必要があると思います。そうでない場合は、どこかで調べて、自分で実装してみてください。