getting closer, need to spread out board cells though
git-svn-id: svn://anubis/gvsu@85 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
a6db811fb2
commit
e9ded6a43c
@ -7,12 +7,18 @@ import javax.swing.border.*;
|
|||||||
|
|
||||||
public class KnightsTour extends JFrame
|
public class KnightsTour extends JFrame
|
||||||
{
|
{
|
||||||
|
private KnightsTourBoard m_ktBoard = new KnightsTourBoard(5, 5);
|
||||||
|
|
||||||
|
/* GUI elements */
|
||||||
private ActionEventHandler m_handler;
|
private ActionEventHandler m_handler;
|
||||||
private JTextField m_widthField;
|
private JTextField m_widthField;
|
||||||
private JTextField m_heightField;
|
private JTextField m_heightField;
|
||||||
private JTextField m_startXField;
|
private JTextField m_startXField;
|
||||||
private JTextField m_startYField;
|
private JTextField m_startYField;
|
||||||
private JButton m_startButton;
|
private JButton m_startButton;
|
||||||
|
private JPanel m_boardPanel;
|
||||||
|
private JPanel m_boardContainerPanel;
|
||||||
|
private JLabel m_statusLabel;
|
||||||
|
|
||||||
public KnightsTour()
|
public KnightsTour()
|
||||||
{
|
{
|
||||||
@ -23,6 +29,13 @@ public class KnightsTour extends JFrame
|
|||||||
m_handler = new ActionEventHandler(this);
|
m_handler = new ActionEventHandler(this);
|
||||||
|
|
||||||
Container c = getContentPane();
|
Container c = getContentPane();
|
||||||
|
|
||||||
|
m_boardContainerPanel = new JPanel();
|
||||||
|
m_boardContainerPanel.setBorder(
|
||||||
|
BorderFactory.createEmptyBorder(5, 0, 0, 0));
|
||||||
|
createBoardPanel(5, 5);
|
||||||
|
|
||||||
|
/* set up the main window contents */
|
||||||
c.add(new JPanel(new BorderLayout()) {{
|
c.add(new JPanel(new BorderLayout()) {{
|
||||||
setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
|
setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
|
||||||
add(new JPanel() {{
|
add(new JPanel() {{
|
||||||
@ -42,7 +55,7 @@ public class KnightsTour extends JFrame
|
|||||||
add(new Box.Filler(new Dimension(5, 0),
|
add(new Box.Filler(new Dimension(5, 0),
|
||||||
new Dimension(5, 0),
|
new Dimension(5, 0),
|
||||||
new Dimension(5, 0)));
|
new Dimension(5, 0)));
|
||||||
add(new JPanel() {{
|
add(new JPanel() {{ /* starting position panel */
|
||||||
setBorder(BorderFactory.createTitledBorder("Starting Position"));
|
setBorder(BorderFactory.createTitledBorder("Starting Position"));
|
||||||
add(new JPanel() {{
|
add(new JPanel() {{
|
||||||
setBorder(BorderFactory.createEmptyBorder());
|
setBorder(BorderFactory.createEmptyBorder());
|
||||||
@ -56,26 +69,45 @@ public class KnightsTour extends JFrame
|
|||||||
add(new Box.Filler(new Dimension(5, 0),
|
add(new Box.Filler(new Dimension(5, 0),
|
||||||
new Dimension(5, 0),
|
new Dimension(5, 0),
|
||||||
new Dimension(5, 0)));
|
new Dimension(5, 0)));
|
||||||
add(new JPanel() {{
|
add(new JPanel() {{ /* start button panel */
|
||||||
setBorder(BorderFactory.createTitledBorder("Start"));
|
setBorder(BorderFactory.createTitledBorder("Start"));
|
||||||
add(new JPanel() {{
|
add(new JPanel() {{
|
||||||
setBorder(BorderFactory.createEmptyBorder());
|
setBorder(BorderFactory.createEmptyBorder());
|
||||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||||
add(m_startButton = new JButton("Start Knight's Tour"));
|
add(m_startButton = new JButton("Start Knight's Tour"));
|
||||||
|
add(m_statusLabel = new JLabel());
|
||||||
}});
|
}});
|
||||||
}});
|
}});
|
||||||
add(new Box.Filler(new Dimension(0, 0),
|
add(new Box.Filler(new Dimension(0, 0),
|
||||||
new Dimension(Short.MAX_VALUE, 0),
|
new Dimension(Short.MAX_VALUE, 0),
|
||||||
new Dimension(10000, 10000)));
|
new Dimension(10000, 10000)));
|
||||||
}}, BorderLayout.NORTH);
|
}}, BorderLayout.NORTH);
|
||||||
add(new JPanel() {{
|
add(m_boardContainerPanel);
|
||||||
add(new JLabel("hello"));
|
|
||||||
}});
|
|
||||||
}});
|
}});
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createBoardPanel(int width, int height)
|
||||||
|
{
|
||||||
|
if (m_boardPanel != null)
|
||||||
|
m_boardContainerPanel.remove(m_boardPanel);
|
||||||
|
m_boardPanel = new JPanel(new GridLayout(width, height));
|
||||||
|
for (int x = 0; x < width; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < width; y++)
|
||||||
|
{
|
||||||
|
JLabel l = new JLabel(m_ktBoard.getStepAt(x, y) == 0
|
||||||
|
? "h"
|
||||||
|
: new Integer(m_ktBoard.getStepAt(x, y)).toString(),
|
||||||
|
SwingConstants.CENTER);
|
||||||
|
m_boardPanel.add(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_boardContainerPanel.add(m_boardPanel);
|
||||||
|
m_boardContainerPanel.validate();
|
||||||
|
}
|
||||||
|
|
||||||
private class ActionEventHandler implements ActionListener
|
private class ActionEventHandler implements ActionListener
|
||||||
{
|
{
|
||||||
private KnightsTour m_kt;
|
private KnightsTour m_kt;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user