我正在编写一个带有图形显示的简单 Knight's Tour 程序。我已经将它编写为与控制台一起使用,现在我正在尝试传输该代码以便它与摇摆一起使用。我有一个按钮,其动作侦听器启动并操作该过程。这是代码:
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
}
}
});
这就是代码。我希望每个数字以一秒的间隔单独显示,但就目前而言,框架会暂时变为空白,并在完成后突然显示所有数字的结果。有人可以帮忙吗?谢谢你。