aboutsummaryrefslogtreecommitdiff
path: root/src/clojure/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'src/clojure/contrib')
-rw-r--r--src/clojure/contrib/swing_utils.clj12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/clojure/contrib/swing_utils.clj b/src/clojure/contrib/swing_utils.clj
index e14c5855..2feadf1d 100644
--- a/src/clojure/contrib/swing_utils.clj
+++ b/src/clojure/contrib/swing_utils.clj
@@ -14,11 +14,19 @@
;; Created 31 May 2009
(ns clojure.contrib.swing-utils
- (:import java.awt.event.ActionListener))
+ (:import (java.awt.event ActionListener KeyAdapter)))
(defn add-action-listener
"Adds an ActionLister to component. When the action fires, f will be
invoked with the event as its first argument followed by args"
[component f & args]
(.addActionListener component (proxy [ActionListener] []
- (actionPerformed [evt] (apply f evt args)))))
+ (actionPerformed [event] (apply f event args)))))
+
+(defn add-key-typed-listener
+ "Adds a KeyListener to component that only responds to KeyTyped events.
+ When a key is typed, f is invoked with the KeyEvent as its first argument
+ followed by args"
+ [component f & args]
+ (.addKeyListener component (proxy [KeyAdapter] []
+ (keyTyped [event] (apply f event args)))))