Permalink
Browse files

initial commit

  • Loading branch information...
1 parent b200da3 commit fafde2937d62177652dd54797b2b8eae76c5857d @krukow committed Aug 31, 2010
Showing with 46 additions and 1 deletion.
  1. +25 −1 src/swing/core.clj
  2. +21 −0 src/swing/records.clj
View
26 src/swing/core.clj
@@ -1,4 +1,28 @@
(ns swing.core
- (:use [swank.swank :as swank]))
+ (:use [swank.swank :as swank])
+ (:import [javax.swing JFrame JLabel JTextField JButton]
+ [java.awt.event ActionListener]
+ [java.awt GridLayout]))
+
+(defn celsius []
+ (let [frame (JFrame. "Karl Converter")
+ temp-text (JTextField.)
+ celsius-label (JLabel. "Celsius")
+ convert-button (JButton. "Convert")
+ fahrenheit-label (JLabel. "Fahrenheit")]
+
+ (.addActionListener
+ convert-button
+ (reify ActionListener
+ (actionPerformed [this evt]
+ (let [c (. Double parseDouble (.getText temp-text))
+ fahr-text (str (+ 32 (* 1.8 c)) " Fahrenheit")]
+ (.setText fahrenheit-label fahr-text)))))
+
+ (doto frame
+ (.setLayout (GridLayout. 2 2 3 3))
+ (.add temp-text) (.add celsius-label)
+ (.add convert-button) (.add fahrenheit-label)
+ (.setSize 300 80) (.setVisible true))))
View
21 src/swing/records.clj
@@ -0,0 +1,21 @@
+(ns swing.records
+ (:use [swank.swank :as swank]))
+
+(defprotocol Indexed,
+ (at [this, i] "return el at ith pos"),
+ (atwithdef [this, i, d] "...."))
+
+(defprotocol TopScored,
+ (topscore [this] "return topscore"))
+
+(defrecord Highscores [scores],
+ Indexed,
+ (at [this i],
+ (nth scores i))
+ (atwithdef [this i d],
+ (nth scores i d)),
+
+ TopScored,
+ (topscore [this],
+ (at this 0)))
+

0 comments on commit fafde29

Please sign in to comment.