Skip to content

Instantly share code, notes, and snippets.

@MachinesAreUs
Created September 4, 2012 01:08
Show Gist options
  • Save MachinesAreUs/3615461 to your computer and use it in GitHub Desktop.
Save MachinesAreUs/3615461 to your computer and use it in GitHub Desktop.
Hello world in Clojure/Swing
(:use 'seesaw.core)
(def lbl (label "Swing App in Clojure/Seesaw"))
(def btn (button :text "Click me"))
(listen btn :action (fn [e] (config! lbl :text "You clicked me!" )))
(frame :title "Hello Swing in Clojure",
:content (border-panel
:center btn
:south lbl
:vgap 5 :hgap 5 :border 5),
:on-close :exit)
pack!
show! )))
@alcidesfp
Copy link

Se ve bien esa biblioteca externa Seesaw para Clojure. Es reciente AFAIK (2011).
La traducción en Kawa sería algo asi como:

(define-alias BorderLayout java.awt.BorderLayout)
(define-alias JFrame javax.swing.JFrame)

(define label1 (javax.swing.JLabel "Swing app in Scheme/Kawa"))
(define buttn1 (javax.swing.JButton "Click me"
                 action-listener: (lambda (evt)
                                    (label1:setText "You clicked me!"))))
(define frm1 (JFrame "Hello Swing in Kawa" 
               default-close-operation: JFrame:EXIT_ON_CLOSE
               layout: (BorderLayout hgap: 5 vgap: 5)))

(frm1:add buttn1 BorderLayout:CENTER)
(frm1:add label1 BorderLayout:SOUTH)
(frm1:pack)
(frm1:show)

Cabe notar que para las definiciones anteriores, Kawa no utiliza ninguna bilblioteca externa auxiliar, la cual de existir creo que simplificaría mucho mas el código así. Tal vez sería una buena idea proponer algo así como un Seesaw para Kawa.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment