From 94b791c2e921c65746c17b6c28dd546586edd3a8 Mon Sep 17 00:00:00 2001 From: scgilardi Date: Sun, 31 May 2009 15:02:15 +0000 Subject: swing-utils: add-key-typed-listener --- src/clojure/contrib/swing_utils.clj | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'src/clojure') 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))))) -- cgit v1.2.3-18-g5258