diff options
author | scgilardi <scgilardi@gmail.com> | 2009-05-31 15:02:15 +0000 |
---|---|---|
committer | scgilardi <scgilardi@gmail.com> | 2009-05-31 15:02:15 +0000 |
commit | 94b791c2e921c65746c17b6c28dd546586edd3a8 (patch) | |
tree | 0b0f25c9144894a80ee8aee5b4b7333d434bec12 | |
parent | 810e1a63de383c991153b286ad677cce161de60e (diff) |
swing-utils: add-key-typed-listener
-rw-r--r-- | src/clojure/contrib/swing_utils.clj | 12 |
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))))) |