RSS
热门关键字:  java  Ajax  JSP  JSF  Struts
当前位置 : 首页>Java>列表

Jython:Java的Python

来源: 作者: 时间:2007-08-08 点击:
'/' ]

keys 
= swing.JPanel(awt.GridLayout(44))      # do Java class library magic
display = swing.JTextField( )                  # Python data auto-mapped to Java

def push(event):                                # callback for regular keys
    display.replaceSelection(event.actionCommand)

def enter(event):                             # callback for the '=' key
    display.text = str(eval(display.text))    # use Python eval( ) to run expr
    display.selectAll( )

for label in labels:                          # build up button widget grid
    key = swing.JButton(label)                # on press, invoke Python funcs
    if label == '=':
        key.actionPerformed 
= enter
    
else:
        key.actionPerformed 
= push
    keys.add(key)

panel 
= swing.JPanel(awt.BorderLayout( ))      # make a swing panel
panel.add("North", display)                     # text plus key grid in middle
panel.add("Center", keys)
swing.test(panel)                               
# start in a GUI viewer

 

The first thing you should notice is that this is genuine Python codeJython scripts use the same core language that we've been using all along in this book. That's good news, both because Python is such an easy language to use and because you don't need to learn a new, proprietary scripting language to use Jython. It also means that all of Python's high-level language syntax and tools are available. For example, in this script, the Python

共11页: 上一页 [1] [2] [3] [4] 5 [6] [7] [8] [9] [10] [11] 下一页
[收藏] [推荐] [评论] [打印] [关闭]
上一篇:SOA Without SOAP: The Java ME Perspective
下一篇:Windows下Eclipse+CDT+MinGW+wxWidgets软件开发
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?
注册
热点关注
Google Adsense
相关文章