
2008年5月3日
在Groovy 1.6.0 BETA 1中引入了@Bindable这一新的Annotation,该Annotation在Swing编程中使用起来尤为方便,下面给出一个实例供大家参考。其内部的实现原理应该是基于Observer模式的。
点击‘update’按钮,随机更新label的值。请注意,我们仅仅设置了myBean的属性prop的值,未对label进行任何的显式操作(比如setText)
import groovy.beans.Bindable
import groovy.swing.*
import javax.swing.*
import java.awt.*
class MyBean {
@Bindable
String prop
}
def rand = new Random()
def greetings = ['hello, world', 'hello, Groovy', 'hello, 山风小子']
def myBean = new MyBean(prop:greetings[2])
def swing = new SwingBuilder()
def frame = swing.frame(title:'Bindable Demo', location: [100, 100], size:[300, 100]) {
panel(layout: new GridLayout(1, 2)) {
label(text:bind(source:myBean, sourceProperty:'prop'))
button(action(name:'update', closure: {myBean.prop = greetings[rand.nextInt(3)]}))
}
}
frame.setVisible(true)
附:
朝花夕拾——Groovy & Grails
posted @
2008-05-03 16:35 山风小子 阅读(1258) |
评论 (2) |
编辑 收藏
摘要: Groovy 1.6.0 BETA 1终于发布了,除了一些BUG修正外,最令人兴奋的是,Groovy的运行效率有了显著的提升。官方用Great Language Shootout的基准测试得出Groovy 1.6.0 BETA 1的性能相比Groovy 1.5.6 GA,提升了150%~460%。
我利用Groovy 1.6.0 BETA 1将下面解决八皇后问题的代码执行10次,结果如下:
Groovy1.5.6GA : 1360 1156 969 1000 1063 1110 938 1046 1031 954 1062.7
Groovy1.6.0BETA1: 187 171 141 109 187 156 172 141 203 187 165.4
经过计算,Groovy1.6.0BETA1的性能相比Groovy1.5.6GA,提升了542.5%。
阅读全文
posted @
2008-05-03 11:52 山风小子 阅读(1478) |
评论 (5) |
编辑 收藏