Hi, On Jun 14, 8:55 am, rob levy <r.p.l...@gmail.com> wrote:
> (ns ... > ... > (:gen-class > :extends javax.swing.JApplet > ??? :implements java.awt.event.KeyListener)) :implements [java.awt.event.KeyListener] Note: vector. > (defn -init [#^JApplet applet] > ??? addKeyListener ) You probably want :post-init. > (defn -keyPressed [#^JApplet applet #^KeyEvent event] > (let [key (. event getKeyCode)] > (cond (= key (. KeyEvent VK_LEFT)) (dosync (ref-set message "left")) > (= key (. KeyEvent VK_RIGHT)) (dosync (ref-set message "right")) > (= key (. KeyEvent VK_UP)) (dosync (ref-set message "up")) > (= key (. KeyEvent VK_DOWN)) (dosync (ref-set message "down")))) You can simplify this with condp. (condp = key KeyEvent/VK_LEFT .... KeyEvent/VK_RIGHT .... KeyEvent/VK_UP .... KeyEvent/VK_DOWN ....) Concerning the question how to make the applet respond: Dunno what the best way is. I would probably put the KeyListener into a proxy, which drives the necessary changes (changing the refs in your example). In the GUI code I would add listeners to the refs, which update the UI on change. Sincerely Meikel PS: Shameless self-promotion: For proxy: http://kotka.de/blog/2010/03/proxy_gen-class_little_brother.html For gen-class: http://kotka.de/blog/2010/02/gen-class_how_it_works_and_how_to_use_it.html For GUI driving: http://kotka.de/blog/2010/05/Decoupling_Logic_and_GUI.html Hope some of this helps. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en