Created
December 3, 2013 13:18
-
-
Save hnaohiro/7769002 to your computer and use it in GitHub Desktop.
Clojure word count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns wordcount.core | |
(:gen-class) | |
(:use [seesaw core graphics])) | |
(defn text-area [] | |
(scrollable | |
(text :id :txt :multi-line? true :font "MONOSPACED-PLAIN-14"))) | |
(defn count-char [txt] | |
(count (re-seq #"\S" txt))) | |
(defn text-count [e] | |
(alert | |
(count-char (text (select (to-frame e) [:#txt]))))) | |
(defn text-clear [e] | |
(text! (select (to-frame e) [:#txt]) "")) | |
(defn button-area [] | |
(flow-panel | |
:align :center | |
:hgap 5 | |
:items [(button :text "count" :listen [:action text-count]) | |
(button :text "clear" :listen [:action text-clear])])) | |
(defn -main [& args] | |
(let [f (frame :title "word count" | |
:on-close :exit | |
:size [600 :by 400] | |
:content (border-panel :center (text-area) | |
:south (button-area) | |
:vgap 5 :hgap 5 :border 10))] | |
(invoke-later (-> f show!)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment