Created
January 23, 2013 10:50
-
-
Save linkerlin/4604327 to your computer and use it in GitHub Desktop.
A demo for jython and swing
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
#! -*- coding:utf-8 -*- | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
print sys.defaultencoding,u"中文" | |
from java.awt import Color | |
from javax.swing import ImageIcon | |
from javax.swing import JButton | |
from javax.swing import JFrame | |
from javax.swing import JPanel | |
from java.lang import System | |
from java.awt import Dimension | |
from javax.swing import JButton | |
from javax.swing import JFrame | |
from javax.swing import JPanel | |
from javax.swing import BoxLayout | |
from javax.swing import Box | |
import threading | |
import thread | |
class Example(JFrame): | |
def __init__(self): | |
super(Example, self).__init__() | |
self.initUI() | |
def initUI(self): | |
basic = JPanel() | |
basic.setLayout(BoxLayout(basic, BoxLayout.Y_AXIS)) | |
self.add(basic) | |
basic.add(Box.createVerticalGlue()) | |
bottom = JPanel() | |
bottom.setAlignmentX(1.0) | |
bottom.setLayout(BoxLayout(bottom, BoxLayout.X_AXIS)) | |
okButton = JButton("OK", actionPerformed=self.onQuit) | |
closeButton = JButton("Close", actionPerformed=self.onQuit) | |
bottom.add(okButton) | |
bottom.add(Box.createRigidArea(Dimension(5, 0))) | |
bottom.add(closeButton) | |
bottom.add(Box.createRigidArea(Dimension(15, 0))) | |
basic.add(bottom) | |
basic.add(Box.createRigidArea(Dimension(0, 15))) | |
self.setTitle("Buttons") | |
self.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) | |
self.setSize(300, 150) | |
self.setLocationRelativeTo(None) | |
self.setVisible(True) | |
def onQuit(self, e): | |
System.exit(0) | |
if __name__ == '__main__': | |
Example() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment