Created
April 24, 2012 13:42
-
-
Save alcidesfp/2479764 to your computer and use it in GitHub Desktop.
Ejemplo Swing Jython
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 jython | |
#-*- coding: utf-8; mode: Jython -*- | |
"Demuestra el uso de clases Java Swing en Jython" | |
from java.awt import BorderLayout | |
from javax import swing | |
#========================================================================= | |
class SimpleFrame(swing.JFrame): | |
def __init__(self): | |
swing.JFrame.__init__(self) | |
print "Inicializando ...\n" | |
#~ crea controles | |
self.label = swing.JLabel("This is a Swing app in Jython") | |
self.button = swing.JButton("Click me!") | |
#~ inicializa UI | |
self.setTitle("Hola Swing desde Jython") | |
self.add(self.label, BorderLayout.CENTER) | |
self.add(self.button, BorderLayout.SOUTH) | |
self.defaultCloseOperation = swing.JFrame.EXIT_ON_CLOSE | |
self.pack() | |
#~ asigna eventos | |
self.button.addActionListener(lambda event: self.onClickBtn(event)) | |
def onClickBtn(self, event): | |
self.label.setText("Hizo click!") | |
#========================================================================= | |
def main(): | |
frame = SimpleFrame() | |
frame.setVisible(True) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Así es sr, de hecho lo mas que pude lograr sin un lambda es sustituyendo la línea 27 con:
self.button.actionPerformed = self.onClickBtn
pero al parecer esto es específico de Jython y no puede aplicarse en otros lenguajes de la máquina virtual de Java