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
|
||||
{
|
||||
private KnightsTourBoard m_ktBoard = new KnightsTourBoard(5, 5);
|
||||
|
||||
/* GUI elements */
|
||||
private ActionEventHandler m_handler;
|
||||
private JTextField m_widthField;
|
||||
private JTextField m_heightField;
|
||||
private JTextField m_startXField;
|
||||
private JTextField m_startYField;
|
||||
private JButton m_startButton;
|
||||
private JPanel m_boardPanel;
|
||||
private JPanel m_boardContainerPanel;
|
||||
private JLabel m_statusLabel;
|
||||
|
||||
public KnightsTour()
|
||||
{
|
||||
@ -23,6 +29,13 @@ public class KnightsTour extends JFrame
|
||||
m_handler = new ActionEventHandler(this);
|
||||
|
||||
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()) {{
|
||||
setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
|
||||
add(new JPanel() {{
|
||||
@ -42,7 +55,7 @@ public class KnightsTour extends JFrame
|
||||
add(new Box.Filler(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"));
|
||||
add(new JPanel() {{
|
||||
setBorder(BorderFactory.createEmptyBorder());
|
||||
@ -56,26 +69,45 @@ public class KnightsTour extends JFrame
|
||||
add(new Box.Filler(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"));
|
||||
add(new JPanel() {{
|
||||
setBorder(BorderFactory.createEmptyBorder());
|
||||
setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
|
||||
add(m_startButton = new JButton("Start Knight's Tour"));
|
||||
add(m_statusLabel = new JLabel());
|
||||
}});
|
||||
}});
|
||||
add(new Box.Filler(new Dimension(0, 0),
|
||||
new Dimension(Short.MAX_VALUE, 0),
|
||||
new Dimension(10000, 10000)));
|
||||
}}, BorderLayout.NORTH);
|
||||
add(new JPanel() {{
|
||||
add(new JLabel("hello"));
|
||||
}});
|
||||
add(m_boardContainerPanel);
|
||||
}});
|
||||
|
||||
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 KnightsTour m_kt;
|
||||
|
Loading…
x
Reference in New Issue
Block a user