グラフィカルなディスプレイを備えた単純な Knight's Tour プログラムを作成しています。コンソールで動作するように既に書きましたが、今はそのコードを移行して、swing で動作するようにしています。アクションリスナーがプロセスを開始して操作するボタンがあります。コードは次のとおりです。
askButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int[][] tour = getBoard(); // generates a matrix representing a successful knight's tour
int count = 0;
while (count < 64) {
count++;
Location loc = searchFor(count, tour); //gets the location of the int "count" inside the matrix "tour"
board.setVisible(false); //board contains a matrix of JPanels called "grid".
grid[loc.row()][loc.column()].add(new JLabel("" + count)); //adds JLabel to JPanel with the proper number
board.setVisible(true); //reset to visible to show changes
delay(1000); //wait 1000 milliseconds - one second - to allow user to view changes
}
}
});
それがコードです。各数値を1秒間隔で個別に表示したいのですが、このままではフレームがしばらく空白になり、終了すると突然すべての数値が表示された結果が表示されます。誰か助けてくれませんか?ありがとうございました。