95 lines
3.6 KiB
Java
95 lines
3.6 KiB
Java
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import javax.swing.*;
|
|
import javax.swing.event.*;
|
|
import javax.swing.border.*;
|
|
|
|
public class KnightsTour extends JFrame
|
|
{
|
|
private ActionEventHandler m_handler;
|
|
private JTextField m_widthField;
|
|
private JTextField m_heightField;
|
|
private JTextField m_startXField;
|
|
private JTextField m_startYField;
|
|
private JButton m_startButton;
|
|
|
|
public KnightsTour()
|
|
{
|
|
super("Josh's Knights Tour project for CS621");
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
setSize(500, 600);
|
|
|
|
m_handler = new ActionEventHandler(this);
|
|
|
|
Container c = getContentPane();
|
|
c.add(new JPanel(new BorderLayout()) {{
|
|
setBorder(BorderFactory.createEmptyBorder(9, 9, 9, 9));
|
|
add(new JPanel() {{
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 7));
|
|
add(new JPanel() {{ /* board size panel */
|
|
setBorder(BorderFactory.createTitledBorder("Board Size"));
|
|
add(new JPanel() {{
|
|
setBorder(BorderFactory.createEmptyBorder());
|
|
setLayout(new GridLayout(2, 2, 5, 5));
|
|
add(new JLabel("Width:", SwingConstants.RIGHT));
|
|
add(m_widthField = new JTextField("5"));
|
|
add(new JLabel("Height:", SwingConstants.RIGHT));
|
|
add(m_heightField = new JTextField("5"));
|
|
}});
|
|
}});
|
|
add(new Box.Filler(new Dimension(5, 0),
|
|
new Dimension(5, 0),
|
|
new Dimension(5, 0)));
|
|
add(new JPanel() {{
|
|
setBorder(BorderFactory.createTitledBorder("Starting Position"));
|
|
add(new JPanel() {{
|
|
setBorder(BorderFactory.createEmptyBorder());
|
|
setLayout(new GridLayout(2, 2, 5, 5));
|
|
add(new JLabel("Column (X):", SwingConstants.RIGHT));
|
|
add(m_startXField = new JTextField("2"));
|
|
add(new JLabel("Row (Y):", SwingConstants.RIGHT));
|
|
add(m_startYField = new JTextField("2"));
|
|
}});
|
|
}});
|
|
add(new Box.Filler(new Dimension(5, 0),
|
|
new Dimension(5, 0),
|
|
new Dimension(5, 0)));
|
|
add(new JPanel() {{
|
|
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(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"));
|
|
}});
|
|
}});
|
|
|
|
setVisible(true);
|
|
}
|
|
|
|
private class ActionEventHandler implements ActionListener
|
|
{
|
|
private KnightsTour m_kt;
|
|
|
|
public ActionEventHandler(KnightsTour kt) { m_kt = kt; }
|
|
|
|
public void actionPerformed(ActionEvent e)
|
|
{
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args)
|
|
{
|
|
KnightsTour kt = new KnightsTour();
|
|
}
|
|
}
|