X.setProperty(value)
Jython:Java的Python
X.setProperty(value)
as well as the following, which relies on attribute name mapping:
也可以利用属性名映射,采用如下方式:
X.property = value
We can combine both callback and property automation for an even simpler version of the callback code snippet:
组合应用回调与属性自动化,可以生成下面这样的更简单的回调代码:
...
key = swing.JButton(label, actionPerformed=push)
You don't need to use these automation tricks, but again, they make Jython scripts simpler, which is most of the point behind mixing Python with Java.
你不必非得使用这些自动化的窍门,但是这些窍门简化了Jython脚本,而简化是混合Python与Java的主旨。
18.4.5. Writing Java Applets in Jython
18.4.5. 用Jython写Java Applet
I would be remiss if I didn't include a brief example of Jython code that more directly masquerades as a Java applet: code that lives on a server machine but is downloaded to and run on the client machine when its Internet address is referenced. Most of the magic behind this is subclassing the appropriate Java class in a Jython script, demonstrated in Example 18-6.
如果我不包含一个Jython代码作为Java applet的简例,那将是我的疏忽。Java applet是放在服务器上的代码,能通过指定网址下载到客户端并运行。Jython代码能够直接地伪装成Java applet。其背后主要的玄机在于Jython脚本类继承了Java Applets类,见例18-6。
Example 18-6. PP3E\Internet\Other\Jython\jyapplet.py
#######################################
# a simple Java applet coded in Python
#######################################
from java.applet import Applet # get Java superclass
class Hello(Applet):
def paint(self, gc): # on paint callback
gc.drawString("Hello applet world", 20, 30) # draw text message
if _ _name_ _ == '_ _main_ _': # if run standalone

