我对 JavaFX 和 GroovyFX 还很陌生。
我刚刚在 JavaFX 上构建了我的第一个表单,一旦我开始工作,我就将它移植到 GroovyFX,因为我在 Groovy/Grails 开发团队中。
我想知道如何模块化页面布局,即如何提取GroovyFX.start()
方法下的节点定义。
假设我有以下简单的布局:
start{
stage(title: 'GroovyFX Hello World', visible: true){
scene(width: 300, height: 100){
borderPane{
center(align: CENTER){
text "this is the center region"
}
}
}
}
}
我可以在 start 方法下将代码提取到闭包中:
start{
def renderCenter = {
text "this is the center region defined in a closure"
}
stage(title: 'GroovyFX Hello World', visible: true){
scene(width: 300, height: 100){
borderPane{
center(align: CENTER){
renderCenter()
}
}
}
}
}
但我想要的是:
class CenterRegion {
def render(){
text "this is the center region in a separate class"
// and other stuff
}
}
start{
stage(title: 'GroovyFX Hello World', visible: true){
scene(width: 300, height: 100){
borderPane{
center(align: CENTER){
CenterRegion.render()
}
}
}
}
}
如何使用 GroovyFX 完成此任务?
谢谢