最后一步是将FXDNode节点指定给Scene对象的content属性。全部代码如下所示:
/*
* Chapter6.fx
*
* v1.0 - J. F. DiMarzio
*
* 5/17/2010 – created
*
* Working with images
*
*/
package com.jfdimarzio.javafxforbeginners;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.fxd.FXDNode;
var butterflyGroup : FXDNode = FXDNode{
url:"{__DIR__}images/butterfly.fxz"
};
var butterfly = butterflyGroup.getNode("butterfly");
butterfly.translateX = 50;
butterfly.translateY = 50;
butterfly.rotate = 45;
/**
* @author JFDiMarzio
*/
Stage {
title : "FXZ Images"
scene: Scene {
content:[ butterflyGroup]
}
}
使用Desktop配置文件运行代码,可看到butterfly图层已经旋转移动到背景下,如图6-7所示。