diff --git a/src/test/GUITest.java b/src/test/GUITest.java index 9a58bbc..0cacc2d 100644 --- a/src/test/GUITest.java +++ b/src/test/GUITest.java @@ -28,5 +28,6 @@ public class GUITest { // handle exception } CheckersWindow window = new CheckersWindow(); + window.open(); } } diff --git a/src/view/Checker.java b/src/view/Checker.java index 7ab90f6..421aeba 100644 --- a/src/view/Checker.java +++ b/src/view/Checker.java @@ -8,6 +8,7 @@ import javax.swing.*; * @author john * */ +@SuppressWarnings("serial") public class Checker extends JPanel { /* The color of the checker */ diff --git a/src/view/CheckersCanvas.java b/src/view/CheckersCanvas.java index 5a62611..ee2b11a 100644 --- a/src/view/CheckersCanvas.java +++ b/src/view/CheckersCanvas.java @@ -9,6 +9,7 @@ import javax.swing.JPanel; import model.Location; +@SuppressWarnings("serial") public class CheckersCanvas extends JPanel { public static final int BOARD_DIM = 8; diff --git a/src/view/CheckersWindow.java b/src/view/CheckersWindow.java index 6036ae7..a1e92bc 100644 --- a/src/view/CheckersWindow.java +++ b/src/view/CheckersWindow.java @@ -1,24 +1,28 @@ package view; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JPanel; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import javax.swing.JOptionPane; - +@SuppressWarnings("serial") public class CheckersWindow extends JFrame { - + /* Constants for the size of the window */ public static final int HEIGHT = 868; public static final int WIDTH = 800; + + /** + * The {@link GamePanel} instance which contains all of the game's visual + * components. + */ private GamePanel gamePanel; + + /** + * The {@link GameEventListener} instance which will be listening to all + * of the game panel's component's + */ private GameEventListener gameListener; @@ -28,61 +32,64 @@ public class CheckersWindow extends JFrame { this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setResizable(false); this.setLocationRelativeTo(null); - this.createMenuBar(); + + /* MUST be done in this order */ this.initGameListener(); + this.createMenuBar(); this.initGamePanel(); - this.setVisible(true); this.pack(); } + /** + * Opens the window by setting the frame's visibility + */ + public void open() { + this.setVisible(true); + } + + /** + * Initializes the {@link GameEventListener} instance. + */ private void initGameListener() { this.gameListener = new GameEventListener(); } + /** + * Initializes the frame's menu bar and all of its items. + */ private void createMenuBar() { JMenuBar menubar = new JMenuBar(); JMenu file = new JMenu("File"); - //New Game + /* New Game Option */ JMenuItem newGame = new JMenuItem("New game"); newGame.setMnemonic(KeyEvent.VK_N); newGame.setToolTipText("Start a new game"); - newGame.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - //this.getContentPane().add(new CheckersCanvas(), BorderLayout.CENTER); - } - }); - //Quit + newGame.addActionListener(gameListener); + + /* Quit Option */ JMenuItem quit = new JMenuItem("Quit"); quit.setMnemonic(KeyEvent.VK_Q); quit.setToolTipText("Exit application"); - quit.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - System.exit(0); - } - }); - //Rules + quit.addActionListener(gameListener); + + /* Instructions Option */ JMenuItem instructions = new JMenuItem("Instructions"); instructions.setMnemonic(KeyEvent.VK_I); instructions.setToolTipText("How to play"); - instructions.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - JOptionPane.showMessageDialog(null, "
selected
member to.
+ */
public void setSelected(boolean val) {
if (val) {
this.setBorder(BorderFactory.createLineBorder(Color.WHITE));
@@ -76,41 +99,34 @@ public class Square extends JPanel implements MouseListener {
this.selected = val;
}
+ /**
+ * Check's if the square contains a {@link Checker} object or not.
+ * @return true
if the square contains a checker. false
otherwise.
+ */
public boolean hasPiece() {
return this.piece != null;
}
-
+
@Override
- public void mouseClicked(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
+ public void mousePressed(MouseEvent e) {
+ /* Send the event to the lister of the square (GameEventListener) */
+ MouseEvent newE = new MouseEvent(this, e.getID(), e.getWhen(), e.getModifiers(),
+ e.getClickCount(), e.getX(), e.getY(), e.isPopupTrigger());
+ this.dispatchEvent(newE);
}
@Override
- public void mouseEntered(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
+ public void mouseClicked(MouseEvent arg0) {}
@Override
- public void mouseExited(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
+ public void mouseEntered(MouseEvent arg0) {}
@Override
- public void mousePressed(MouseEvent e) {
- MouseEvent newE = new MouseEvent(this, e.getID(), e.getWhen(), e.getModifiers(),
- e.getClickCount(), e.getX(), e.getY(), e.isPopupTrigger());
- //this.dispatchEvent(newE);
-
- }
+ public void mouseExited(MouseEvent arg0) {}
@Override
- public void mouseReleased(MouseEvent arg0) {
- // TODO Auto-generated method stub
-
- }
+ public void mouseReleased(MouseEvent arg0) {}
}