(See my full list of Clojure Swing examples and tutorials at Clojure Swing Interop)
Here’s a really brief example for building a Java Swing app using Clojure.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
(ns myswingproject.core (:import [javax.swing SwingUtilities JFrame JLabel])) (defn create-and-show-gui [] (let [my-frame (doto (JFrame. "My Frame") (.setDefaultCloseOperation JFrame/EXIT_ON_CLOSE)) my-label (JLabel. "Hello UI") content-pane (.getContentPane my-frame)] (.add content-pane my-label) (.pack my-frame) (.setVisible my-frame true))) (defn gui [] (SwingUtilities/invokeLater create-and-show-gui)) (gui) |