See All Titles |
![]() ![]() Creating Graphical InterfacesWindowing applications are written in JPython using the same set of options that you have available for Java applications. Currently, the two names that you will hear most for this kind of implementation are awt and swing. AWT stands for Abstract Windowing Toolkit, which is the official name for the Java GUI. Note that the syntax is very similar to Tkinter, thus it will not be a problem for you to understand and use it. import java frame = java.awt.Frame("Ni!", visible = 1) labeltop = java.awt.Label("Hello Python World!") frame.add(labeltop) frame.pack() JPython also contains a package called pawt (stands for Python AWT), which wrappes the access to awt, providing some additional functionality. The successor of Java's windowing toolkit is provided as part of the Java Foundation Classes. This set of classes extends the original AWT by adding a comprehensive set of graphical user interface class libraries, commonly known as JFC/Swing GUI Components, or simply Swing. These components are simple to read and understand, and they are written in the Java programming language, without window-system–specific code. This causes less problems when distributing JPython applications because you do not rely on the code of a specific windowing system. For details, see http://java.sun.com/products/jfc/. At this page, you can download the latest version of the Java Foundation Classes (JFC)/Swing, which at this moment is in release 1.1.1. After downloading it, make sure that you have the following environment variables correctly defined: JAVA_HOME, SWING_HOME, CLASSPATH, and PATH. Next, you have the section of the autoexec.bat of my Win98 machine that handles these definitions, for your information. set JAVA_HOME=C:\ JDK1.1.8 set SWING_HOME=C:\ JDK1.1.8\ swing-1.1.1 set PATH=%PATH%;%JAVA_HOME%\ bin set CLASSPATH=.;%JAVA_HOME%\ lib\ classes.zip set CLASSPATH=%CLASSPATH%;%SWING_HOME%;%SWING_HOME%\ swing.jar; set CLASSPATH=%CLASSPATH%;%SWING_HOME%\ windows.jar The next code shows an example that uses the Python package pawt to access the swing components. import java import pawt def exit(h): java.lang.System.exit(0) frame = pawt.swing.JFrame('Ni! again!', visible=1) display = pawt.swing.JTextField() display.text = "Click on the button below to exit!" frame.contentPane.add(display) button = pawt.swing.JButton('Exit', actionPerformed=exit) frame.contentPane.add(button) frame.pack()
|
Index terms contained in this sectionAbstract Windowing Toolkit (AWT) 2ndaccessing swing components AWT (Abstract Windowing Toolkit) AWT Abstract Windowing Toolkit classes Java Foundation (JFC) components swing accessing graphical user interfaces (GUIs) Abstract Windowing Toolkit (AWT) 2nd interfaces graphical user (GUI) Abstract Windowing Toolkit (AWT) 2nd Java Foundation Classes (JFC) JFC (Java Foundation Classes) JFC/Swing GUI Components (Swing) library libraries JFC/Swing GUI Components (Swing) packages pawt accessing swing components pawt package accessing swing components Swing (JFC/Swing GUI Components) library swing components accessing |
© 2002, O'Reilly & Associates, Inc. |