Skip to content

Instantly share code, notes, and snippets.

@alcidesfp
Created April 24, 2012 13:40
Show Gist options
  • Save alcidesfp/2479748 to your computer and use it in GitHub Desktop.
Save alcidesfp/2479748 to your computer and use it in GitHub Desktop.
Ejemplo Swing JRuby
#! /usr/bin/env jruby
# -*- coding:utf-8; -*-
'Demuestra el uso de clases Java Swing en JRuby'
require 'java'
#=========================================================================
class SimpleFrame < javax.swing.JFrame
def initialize
super
puts 'Inicializando ...'
#~ crea controles
@label = javax.swing.JLabel.new('A Swing app in JRuby')
@button = javax.swing.JButton.new('Click me!')
#~ inicializa UI
self.setTitle("Hola Swing desde JRuby")
self.add(@label, java.awt.BorderLayout::CENTER)
self.add(@button, java.awt.BorderLayout::SOUTH)
self.setDefaultCloseOperation(javax.swing.JFrame::EXIT_ON_CLOSE)
self.pack
#~ asigna eventos
@button.addActionListener { |event| self.onClickBtn(event) }
end
def onClickBtn(event)
@label.setText('¡Hizo click!')
end
end
#=========================================================================
def main
frame = SimpleFrame.new
frame.setVisible(true)
end
if $0 == __FILE__
main
end
@alcidesfp
Copy link
Author

Si, de hecho el lambda en Jython se me ocurrió ponerlo después de haber visto el bloque en JRuby

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