Skip to content

Instantly share code, notes, and snippets.

@alcidesfp
Last active October 15, 2015 05:49
Show Gist options
  • Save alcidesfp/2492398 to your computer and use it in GitHub Desktop.
Save alcidesfp/2492398 to your computer and use it in GitHub Desktop.
Ejemplo Swing Kawa
;; -*- coding:utf-8; mode:Scheme -*-
"Shows howto use Java Swing classes in Kawa Scheme"
(define-alias JLabel javax.swing.JLabel)
(define-alias JButton javax.swing.JButton)
;;========================================================================
(define-simple-class SimpleFrame (javax.swing.JFrame)
;; members
(label ::JLabel init: (JLabel "Swing Application in Kawa"))
(button init: (JButton "Click Me!"
action-listener: (lambda (event)(on-click-btn))))
;;----------------------------------------------------------------------
;; methods
((*init*) ;constructor
(invoke-special javax.swing.JFrame (this) '*init* "Hello Swing in Kawa")
(format #t "Initializing ...~%")
;; initialize UI
(add label java.awt.BorderLayout:CENTER)
(add button java.awt.BorderLayout:SOUTH)
(setDefaultCloseOperation javax.swing.JFrame:EXIT_ON_CLOSE)
(pack))
;;----------------------------------------------------------------------
((on-click-btn) ;event handler
(label:setText "You clicked the button!")))
;;========================================================================
(define (main)
(let ((frame (SimpleFrame)))
(frame:setVisible #t)))
(main)
@alcidesfp
Copy link
Author

No, de hecho las definiciones de clases en Kawa no son inmutables, esta es una diferencia con respecto a Clojure AFAIK.

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