Created
April 24, 2012 13:40
-
-
Save alcidesfp/2479748 to your computer and use it in GitHub Desktop.
Ejemplo Swing JRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Si, de hecho el lambda en Jython se me ocurrió ponerlo después de haber visto el bloque en JRuby