Source

neman / examples / swing2.clj

Full commit
(ns user
  (:import
    (java.awt FlowLayout)
    (javax.swing JFrame JButton JLabel JOptionPane))
  (:use
    (net.ksojat.neman
      core
      [cells :only [cell cell-set! bind]]
      [swing :only [swing doswing]])))

(def user-input (cell ""))

(defn run-it []
  (swing
    (=> (JFrame. "Frame")
      :Size [500 300]
      :DefaultCloseOperation JFrame/DISPOSE_ON_CLOSE
      :Layout (FlowLayout.)

      [(=> ~button1 (JButton. "Input")
         (>> :actionPerformed
            (fn [e]
              (.setText button2 "Output's New Label")
              (cell-set! user-input
                (JOptionPane/showInputDialog nil "Type in something")))))

       (=> ~button2 (JButton. "Output")
         (>> :actionPerformed
            (fn [e]
              (.setText button2 "Output")
              (JOptionPane/showMessageDialog nil @user-input))))

       (=> (JLabel. @user-input)
         ~(bind :text [user-input] [v] v))]

      :Visible true)))

(doswing
  (run-it))