I spent a few hours writing a macro that would allow a more
declarative gui than the usual swing approach. I didn't finish it, but
concluded that this could be quite doable. For example, I was aiming
for a macro that would allow the following declarative style:
[Note that I don't have the actual code or example that I had working
since that is on my laptop hibernating at home atm.]

; rough example
(make-ui
  '(JFrame {:title "The title"}
    (JLabel {:id fooLabel :text "Some label"})
    (JButton {:id btn1 :label "Click me" :actionPerformed (fn [evt]
(println "clicked")) })
    (JButton {:label "Apply" :actionPerformed someFn :enabled false })))

This doesn't address the functional/stateless impedance mismatch, but
would make defining guis simpler. However, the basic idea is to
represent the containment hierarchy inherent in a gui with the nesting
of lisp expressions. The map of attributes would be applied as setters
on each component after it is created. The event handlers such as
":actionPerformed" are harder, but also doable.

The nasty part that I haven't spent any time thinking about is the
LayoutManager gong show in swing. That sounds much harder to solve
declaratively without writing a bunch of LMs that support simplifying
the declarative style.

Michael

On Wed, Oct 8, 2008 at 3:37 PM, Bob <[EMAIL PROTECTED]> wrote:
>
> Yes, I'm very interested in this question as well.  I'm learning
> clojure and its my first attempt at functional programming.  And I was
> thinking of writing a swing GUI program to try it out.  But it would
> seem the GUI state is going to be a mass of mutable state which
> doesn't map well to the functional style.  What am I missing?  Does
> anyone have a non-trivial example of a Swing program done the Clojure
> way?
>
> Thanks much,
> Bob
>
> On Oct 8, 2:07 pm, Mitch <[EMAIL PROTECTED]> wrote:
>> I'm interested in doing a GUI program in clojure, but the functional
>> style of clojure doesn't seem to blend too well with the normal Java
>> GUI libraries.  Does anybody have any advice on using clojure for GUI
>> programming?  I've seen Rich's ants demo, but that isn't really an
>> event driven GUI program (just a nice display for his simulation).
>> Has anyone tried using of the GUI building tools for Java with
>> clojure?  I feel like these could help a lot, but I'm not sure.
>>
>> Thanks,
>> Mitch
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to