Skip to content

Instantly share code, notes, and snippets.

@mistercam
Created April 29, 2012 18:07
Show Gist options
  • Save mistercam/2552324 to your computer and use it in GitHub Desktop.
Save mistercam/2552324 to your computer and use it in GitHub Desktop.
Function that starts a Swing-based Reversi game
(defn reversi-swing []
"Starts a Swing-based Reversi game."
(let [board (atom (initialize-board)) ; the active board (mutable)
piece (atom :b) ; the active piece (mutable)
frame (JFrame. "Reversi") ; the outer Swing container. "Reversi" appears in the title bar.
panel (reversi-panel frame board piece)] ; the Reversi board
(doto panel
(.setFocusable true) ; focus can be given to this panel
(.addMouseListener panel)) ; have the panel listen for mouse events
(doto frame
(.add panel) ; add our Reversi panel to the frame
(.pack) ; size the frame to fit the preferred size of our panel
(.setVisible true)))) ; make the frame visible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment