Meikel,

Thank you!  This gives me some ideas I'm going try.  I read your blog posts
too, great stuff.

The new book by Vanderhart & Sierra serves as good documentation of proxy as
well.

I have not yet come across a good "Java for Clojure Programmers" guide that
really explores all the hairy problems of operating Java libraries via
Clojure.  Maybe there should be a wiki for this.  I think a lot of Clojurers
are dynamic language folk like me who have avoided Java for the most part
(actually my computer science courses used Java, so I could only imagine the
learning curve must be even worse for some people).

Rob


On Mon, Jun 14, 2010 at 3:52 AM, Meikel Brandmeyer <m...@kotka.de> wrote:

> 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<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

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