From: Kent J. <ke...@td...> - 2005-01-22 13:48:02
|
Red Crow wrote: > Hello: > > I'm interesting about the use swing with jython, > where I found more about this teme? It's pretty straightforward if you know Jython and Swing. Here is a simple & complete example. There are also a few short examples included in the Jython distribution. If you don't know Swing, the documentation from Sun is pretty good, look at the Java docs and the Swing tutorial. Kent ''' Simple demo of Jython and Swing ''' from __future__ import nested_scopes import sys from java.awt import GridLayout from javax.swing import JButton, JFrame, JLabel, JPanel increments = [1, 10, -1, -10] class TestFrame(JFrame): def __init__(self, title, **kwd): JFrame.__init__(self, title, **kwd) self.contentPane.setLayout(GridLayout(1, 2)) # Make a button panel with Add buttons for each increment and a Reset button buttonPanel = JPanel(GridLayout(0, 1)) for inc in increments: button = JButton('Add ' + str(inc)) button.actionPerformed = lambda evt, inc=inc: self.bumpBy(inc) buttonPanel.add(button) resetButton = JButton('Reset', actionPerformed = self.reset) buttonPanel.add(resetButton) self.contentPane.add(buttonPanel) # Make a counter centered in the right side self.counter = JLabel('0', JLabel.CENTER) self.contentPane.add(self.counter) def bumpBy(self, inc): ''' Increment the counter by inc ''' value = self.counter.getText() value = int(value) + inc self.counter.setText(str(value)) def reset(self, evt): self.counter.setText('0') if __name__ == '__main__': f = TestFrame('Test Window', windowClosing=lambda event: sys.exit(0)) f.pack() f.setVisible(1) |