Hi All,

I've been able to figure out many Java things based on Sun's online
documentation, and this is undoubtedly due to my not being a Java
programmer, but for the life of me I can't figure out based on Java examples
how to get my Clojure JApplets to respond to keyboard input.  Does anyone
have any ideas as to how to go about doing this?

(set! *warn-on-reflection* true)

(ns ...
    ...
    (:gen-class
     :extends javax.swing.JApplet
  ???   :implements java.awt.event.KeyListener))
...

(defn -init [#^JApplet applet]
  ??? addKeyListener )

(defn -paint [#^JApplet applet #^Graphics g]
   ...
   (.drawString #^String @message 60 40)
   ...)

(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"))))
  (. applet repaint))



Thanks,
Rob

-- 
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

Reply via email to