Skip to content

Instantly share code, notes, and snippets.

@remram44
Created June 5, 2012 21:04
Show Gist options
  • Select an option

  • Save remram44/2877919 to your computer and use it in GitHub Desktop.

Select an option

Save remram44/2877919 to your computer and use it in GitHub Desktop.
Swing from Jython - threading issues
import threading
from javax.swing import JFrame, JButton
from java.awt.event import ActionListener, WindowAdapter
class Frame(JFrame, ActionListener):
def __init__(self):
print "constructing! thread is %s" % threading.currentThread()
button = JButton("Hello")
button.setActionCommand('button')
button.addActionListener(self)
self.getContentPane().add(button)
self.pack()
self.setResizable(False)
# @Override
def actionPerformed(self, event):
print "event! thread is %s" % threading.currentThread()
endCondition = threading.Condition()
class Adapter(WindowAdapter):
# @Override
def windowClosing(self, event):
endCondition.acquire()
endCondition.notifyAll()
endCondition.release()
if __name__ == '__main__':
endCondition.acquire()
frame = Frame()
frame.setVisible(True)
frame.addWindowListener(Adapter())
# We don't use setDefaultCloseOperation(EXIT_ON_CLOSE), which would call
# Java's System.exit() instead of Python's sys.exit()
endCondition.wait()
endCondition.release()
print 'sys.exit()'
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment