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 height = m_ktBoard.getHeight();
|
||||
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));
|
||||
for (int x = 0; x < width; x++)
|
||||
{
|
||||
@ -146,16 +146,47 @@ public class KnightsTour extends JFrame
|
||||
m_ktBoard = new KnightsTourBoard(width, height);
|
||||
createBoardPanel();
|
||||
|
||||
/* run the tour and update GUI */
|
||||
if (m_ktBoard.tour(startx, starty))
|
||||
{
|
||||
createBoardPanel();
|
||||
m_statusLabel.setText("Finished.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_statusLabel.setText("Solution not found!");
|
||||
}
|
||||
/* run the tour in a separate thread */
|
||||
m_startButton.setEnabled(false);
|
||||
|
||||
new Thread(new TourThread(startx, starty)).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class TourThread implements Runnable
|
||||
{
|
||||
int m_startx, m_starty;
|
||||
|
||||
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