A GUI Application

Now let's create a GUI based on our prototype in both Jython and Java. The following example shows our Python employee form; after that is its Java equivalent.

Python:

 from javax.swing import JFrame, JButton, JTextField, JLabel, JPanel from string import split from pawt import GridBag from Employee import Employee class EmployeeForm(JFrame): def __init__(self): JFrame.__init__(self, "Employee Form") pane = JPanel() self.contentPane.add(pane) bag = GridBag(pane) #Create a name and id text field. self.__name = JTextField(25) self.__id = JTextField(10) #Create and add a "Name" and "ID" label. name = JLabel("Name", labelFor=self.__name, displayedMnemonic=ord('N')) bag.add(name) id = JLabel("ID", labelFor=self.__id, displayedMnemonic=ord('I')) ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.