switched rows/columns for GridLayout
git-svn-id: svn://anubis/gvsu@90 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
66748cb762
commit
1faf4bdb9b
@ -89,7 +89,7 @@ public class KnightsTour extends JFrame
|
|||||||
int width = m_ktBoard.getWidth();
|
int width = m_ktBoard.getWidth();
|
||||||
int height = m_ktBoard.getHeight();
|
int height = m_ktBoard.getHeight();
|
||||||
JPanel oldBoardPanel = m_boardPanel;
|
JPanel oldBoardPanel = m_boardPanel;
|
||||||
m_boardPanel = new JPanel(new GridLayout(width, height, 1, 1));
|
m_boardPanel = new JPanel(new GridLayout(height, width, 1, 1));
|
||||||
m_boardPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
m_boardPanel.setBorder(BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||||
for (int x = 0; x < width; x++)
|
for (int x = 0; x < width; x++)
|
||||||
{
|
{
|
||||||
@ -145,17 +145,48 @@ public class KnightsTour extends JFrame
|
|||||||
/* create a new KnightsTourBoard object */
|
/* create a new KnightsTourBoard object */
|
||||||
m_ktBoard = new KnightsTourBoard(width, height);
|
m_ktBoard = new KnightsTourBoard(width, height);
|
||||||
createBoardPanel();
|
createBoardPanel();
|
||||||
|
|
||||||
|
/* run the tour in a separate thread */
|
||||||
|
m_startButton.setEnabled(false);
|
||||||
|
|
||||||
/* run the tour and update GUI */
|
new Thread(new TourThread(startx, starty)).start();
|
||||||
if (m_ktBoard.tour(startx, starty))
|
}
|
||||||
{
|
}
|
||||||
createBoardPanel();
|
}
|
||||||
m_statusLabel.setText("Finished.");
|
|
||||||
}
|
private class TourThread implements Runnable
|
||||||
else
|
{
|
||||||
{
|
int m_startx, m_starty;
|
||||||
m_statusLabel.setText("Solution not found!");
|
|
||||||
}
|
public TourThread(int startx, int starty)
|
||||||
|
{
|
||||||
|
m_startx = startx;
|
||||||
|
m_starty = starty;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
if (m_ktBoard.tour(m_startx, m_starty))
|
||||||
|
{
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
createBoardPanel();
|
||||||
|
m_statusLabel.setText("Finished.");
|
||||||
|
m_startButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
createBoardPanel();
|
||||||
|
m_statusLabel.setText("Solution not found!");
|
||||||
|
m_startButton.setEnabled(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user