- 浏览: 1431204 次
- 性别:
- 来自: 北京
最新评论
-
w0014019862:
引用[img][url][/url][/img]
短信开发技术总结--协议篇 -
wxq:
很详细!
电子商务网站(淘宝网)的系统架构解析 -
yong0902:
这个确实可以,感谢楼主
用spapi.jar开发包通过联通平台发长短信 -
phk070832:
为什么你的代码每次都要先设置一个产品,然后才能取出一个产品,而 ...
Java线程间同步实现生产者-消费者模式 -
janwen:
好,以前有印象的,现在忘了
Servlet 采用 forward 时,页面出现汉字乱码问题的分析
原文:http://www.javafx.com/docs/gettingstarted/javafx/create-first-javafx-app.jsp
This section guides application developers in creating their first JavaFX application by using the NetBeans IDE 6.5 for JavaFX 1.0technology. For web designers who want to get started using the JavaFX1.0 Production Suite, see the Getting Started With JavaFX 1.0 Production Suite article.
这一章指导应用开发人员使用NetBeans IDE 6.5 for JavaFC 1.0 技术来创建第一个 Java FX 应用.对于想使用JavaFX 1.0 Production Suite 的 Web 设计人员,看这个文章 Getting Started With JavaFX 1.0 Production Suite 。
In this section, you create a simple sphere with text that changes color and performs a scaling transformation within a specified timeperiod, as shown next:
这一章,你要创建一个简单的球体。包含可以改变颜色和执行一个指定时间周期的平滑变化的文字,如下所示:
JAVA世纪网 http://www.java2000.net
Figure 1: Finished JavaFX Sphere
完成的JavaF 球体
1. Ensure that you have the NetBeans IDE 6.5 for JavaFX 1.0 software already installed on your system. If necessary, revisit the What to Download page.
确信你已经安装了NetBeans IDE 6.5 for JavaFX 1.0 软件。
2. Start the NetBeans IDE.
启动 NetBeans IDE
a. For Windows. Choose Start > All Programs > NetBeans > NetBeans IDE 6.5
在Windwos 平台,选择 Start > All Programs > NetBeans > NetBeans IDE 6.5
b. For Mac OS X. Select Applications > NetBeans > NetBeans 6.5
在 MAC OS上,选择 Applications > NetBeans > NetBeans 6.5
3. Create a JavaFX Script Application project.
创建 JavaFC Script 应用项目
a. Choose File > New Project (Ctrl-Shift-N).
选择 File > New Project (Ctrl-Shift-N).
b. Inthe New Project wizard, select JavaFX in the Categories pane and JavaFXScript Application in the Projects pane. Click Next.
在新建项目向导里,在分类面板里面选择 JavaFX,在 项目面板里选择 JavaFXScript 应用,点击[Next]
c. On the Name and Location page, type FirstJavaFXSpherefor the Project Name, specify your desired location for the project's files in the Project Location text field, and leave all other default values unchanged, as shown in Figure 2.
在名字和位置页面,输入[FirstJavaFXSphere]作为项目的名字,指定项目文件的路径,其它的保持默认值不要改变,如图2所示:
Figure 2: New Project Wizard With Project Name and Location Specified.
图2,新建项目向导,项目名称和指定位置 JAVA世纪网 http://www.java2000.net
d. Click Finish.
点击[Finish]
The FirstJavaFXSphere project opens in both the Projects window and the Files window, and the Main.fx file opens in the source editor, as shown in Figure 3.
项目同时在项目窗口和文件窗口打开,Main.fx 被源代码编辑器打开,如图3所示:
Figure 3: FirstJavaFXSphere Project Opened in Projects Window and Main.fx File in the Source Editor.
Notice that JavaFX Script code is included within the Main.fx file by default. This code includes several import statements and object literals (like Stage). These Object literals represent key concepts within a JavaFX application, and are described in the table below.
注意:JavaFX的脚本代码是默认包含在Main.fx 文件里的。代码包含了一些import语句和对象文字。这些对象表示JavaFX里买你的关键概念,将在下面的表格里描述 JAVA世纪网 http://www.java2000.net
Table 1: Object Literals Created by Default
Note: For more information, see Using Objects, a lesson in Learning the JavaFX Script Programming Language.
4. Modify the Stage object, as shown next, so that the window has the title, window size,and text that we want to appear in the application we are building. You also need to add the import statement for the TextAlignment class.
如后面所示,修改场景对象,来让窗口有便同意,窗口尺寸和我们想创建应用要显示的文字。你同样需要增加import语句给TextAlignment 类。
a.Modify the Stage object literal as shown below. You may copy the lines in bold and paste them in the editor.
修改Stage 对象Source Code
源代码
b. To fix the highlighted error due to a missing import statement for the TextAlignment class used, right-click in any white space in the editor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的 TextAlignment 类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I)
The following import statement is added to the top of the Main.fx file.Source Code
import 语句被叫如到Main.fx源代码的最顶部 JAVA世纪网 http://www.java2000.net
5. Define the basic Circle object from which you create the sphere by expanding the Basic Shapes section in the Palette window and dragging the Circle code snippet in the line above the Text code block, as shown next.
从Pallette 窗口拖动 Circle 代码片段来创建球星的基础。
Figure 4: Drag the Circle Code Snippet From the Palette Window.
6. Modify the circle's instance variables so that it has the correct size to contain the text. Also, add a new RadialGradient setting, which makes the circle have a little depth and look more like a sphere.Modifythe source file with the following source code in bold. You can copy the lines in bold, including the closing square and curly braces forthe fill variable, and paste them to the source editor.
修改圆的实例属性到正确的尺寸和文字。同时增加一个 RadialGradient 配置,来让圆看上去有一些深度,更像一个球。如下的粗体部分修改源代码。 JAVA世纪网 http://www.java2000.net
Source Code
b. To fix the errorsthat are highlighted because of the missing import statements forseveral classes introduced in the previous step, right-click in anywhite space in the editor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的 一些类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I) JAVA世纪网 http://www.java2000.net
The following import statements are added to the top of the Main.fx file.
如下的import 语句被加入到Main.fx文件的顶部
Source Code
7. Turn on the Preview feature by clicking the Enable Preview button on the editor toolbar.
点击编辑按扭栏的【 Enable Preview 】按钮来打开预览特性
A new Design Preview window displays the circle you just modified to look more like a sphere, as shown next. The preview feature enables you to view the current state of the GUI design you are creating. As you modify the source code and if no errors are encountered, the design preview window displays the current status of the GUI you are building.
一个设计预览窗口打开,显示你刚才修改的圆看上去更像一个球。预览特性让你可以查看当前GUI设计的状态。当你修改了源代码且没有代码错误,设计预览窗口将显示你当前建立的GUI状态。
Figure 5: Sphere in Designer Preview Window.
8. Use the following steps to change the color of the text to yellow and to add a drop shadow effect.
使用下面的步骤来修改文字颜色为黄色,同时增加一个阴影效果。
a.Add the variables color and scale with their initial default values set.
增加颜色和比例变量以及初始值。
These variables will be used in the timeline animation you will create in later steps.
这些只用与后面步骤的时间线的动画
Source Code
b.Modify the Text object so that the lines defining the fill, effect, and transforms variable instances are added, as shown in bold below. You may copy the lines in bold below and paste it to the source editor.
修改文本对象来定义填充效果和增加转换变量实例。 JAVA世纪网 http://www.java2000.net
Source Code
The fill variable instance binds the Text's color to the variable color. A drop shadow effect is added and the scaling transformation is defined. The transforms variable defines the value of the Scale object returned from the call to the Scale function. The Scale object represents a scaling transformation defined by the specified variables, x, y, pivotX, and pivotY. The x and y variables define the factor by which coordinates are scaled along the x and y axis directions. The pivotX and pivotY variables define the X and Y coordinates about which point the scale occurs.
填充变量实例绑定了文本的颜色为变量的颜色。增加影响效果和定义缩放变换。变换变量定义了缩放的对象调用缩放功能返回的对象。缩放对象 通过缩放的变换变量 x,y,provotX和 provotY定义。 x和y变量定义了沿着x和y坐标缩放的比例参数。 privotX和privotY变量定义了发生缩放的点的X和Y坐标。
To correct the highlighted errors due to the missing import statements forthe two classes introduced, right-click in any white space in theeditor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的2个类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I)
Select the javafx.scene.effect.DropShadow in the first dialog, as shown in Figure 6, and press Enter. In the next pop-up dialog, select the javafx.scene.transform.Scale and press Enter.
在第一个对话框里选择 javafx.scene.effect.DropShadow,按回车,在下一个弹出对话框里选择 javafx.scene.transform.Scale然后回车。 JAVA世纪网 http://www.java2000.net
Figure 6: Fix Imports pop-up dialog.
The following import statement is added to the top of the Main.fx file.
下面的import语句被加入到Main.fx文件的顶部
Source Code
Notice in the Design Preview window that the text's color has changed to yellow and the drop shadow effect now appears, as shown next.
注意设计预览窗口的文字颜色已经变成黄色,阴影效果也出现了。
Figure 7: Sphere Updated in the Designer Preview Window.
9. Add animation by having the text change from yellow to green and have it rotate.
增加文字从黄色到绿色的动画效果,然后循环
a. Expand the Animation section in the Palette window, select Timeline, and drag the Timeline code snippet to the line just above the Stage code block, as shown next.
打开 Pallette 窗口的 Animation 区,选择 Timeline(时间线),拖动Timeline 代码片段到刚好在Stage代码块的上面。
Figure 8: Drag Timeline Code Snippet from the Palette to the Source Editor.
Animation occurs along a timeline, represented by a javafx.animation.Timeline object. Each timeline contains one or more key frames, represented by javafx.animation.KeyFrame objects.For more information about animation, see Creating Animated Objects, a lesson in Building GUI Applications With JavaFX.
动画沿着时间线发生,通过 javafx.animation.Timeline对象实现。每个时间线包含一个或多个关键帧,通过 javafx.animation.KeyFrame 对象表示。
b. Change the value of the time instance variable from 1s to 5s so that now the Timeline object literal is as shown below.
修改时间实例的值,从1s 到 5s, 如下所示 JAVA世纪网 http://www.java2000.net
Source Code
This timeline repeats indefinitely on a five second interval. The value of the time instance variable, 5 seconds, defines the elapsed time at which the values within the key frame will be set in a single cycle of the Timeline object. The next couple of steps of this tutorial define those values to be set.
时间线每5秒无限重复。 实例的 time 变量为5秒,表示Timeline 对象在一个循环里关键帧里要消耗的时间。这个向导的后面的步骤定义了这些变量。
c. Drag the Animation > Values code snippet from the Palette to the line just after time variable.
拖动 Animation > Values 代码片段从 Pallette 到 time 变量的后面
Figure 9: Drag Values Code Snippet from the Palette to the Source Editor.
Values define the list of target variables and the desired values they should interpolate at the specified time of the KeyFrame.
变量Values定义了一系列目标变量和KeyFrame希望插入使用的变量。
d. Copy the lines shown in bold below and paste it to the source editor to modify the values instance. The added code changes the text's color from yellow to green as it eases.
复制后面的粗体部分代码,粘贴到你的代码里面。 JAVA世纪网 http://www.java2000.net
Source Code
The desired values of the scale and color variables are defined within the 5 seconds interval of the keyframe. The =>operator provides a literal constructor (a special notation) that makesit easier to express the list of key interpolated values or object properties.
要使用的缩放和颜色变量被定义在关键帧的5秒周期内。 => 操作符提供了一个结构,来简单的描述一系列的关键插入值和对象属性。
In this case, we use the tween operator to construct the interpolated values for the scale between 1.0 and -1.0 to create the illusion of rotation. The Interpolator.EASEBOTH is the built-in interpolator instance that provides for ease in and out behavior. Also, over the same 5 second period, the color of the text will change from yellow to green.
在这个情况下,我们使用 tween 操作符来构建一个内插的数值,从1.0到 -1.0 来创建一个旋转的现象。Interpolator.EASEBOTH 是内建的内插实例,来提供擦除内部和外部的功能。同样,在5秒的周期内,文本的颜色将从黄色变成绿色。 JAVA世纪网 http://www.java2000.net
Right-click in any white space in the editor and select Format (Alt+Shift+F) to properly align the newly added lines of code.Add .play(); to the end of the Timeline object declaration, as shown below in bold.
在任何编辑的空白地方点右键,选择 Format (Alt+Shift+F) 来让新增加的代码行正确对齐。在Timeline对象的末尾增加 .play()
The play() method plays the timeline as defined. The completed Timeline object should be as shown next.
play方法运行定义的时间线。完整的Timeline对象如下
Source Code
Notice in the Design Preview window that the text's color is now continuously changing from yellow to green as it appears to rotate. Ifyou are not seeing this, click the Reset Preview button.
注意,设计预览窗口里,文字颜色将布点的从黄色变到绿色,并且循环。如果你没有看到这个,那么点一下Reset Preview 按钮。
10. Run the project.
运行项目
Close the Design Preview window.In the Projects window, right-click the FirstJavaFXSphere project node and select Run Project.
关闭设计预览窗口,在项目窗口,右键点击 FirstJavaFXSphere 项目节点,选择 Run Project.
The IDE compiles the project and prepares the files necessary to run the application using the Desktop execution model. When the project is compiled successfully, an animated sphere similar to what is shown in Figure 1 is displayed. The color of the text should change from yellow to green as it appears to rotate.
IDE编译项目,准备桌面运行模式运行需要的文件。当项目编译成功后,一个模拟的球形动画将显示如图一所示。文本的颜色将从黄色变到绿色,并循环显示。 JAVA世纪网 http://www.java2000.net
Congratulations! You've just created your first JavaFX application.
祝贺你,你已经创建了你第一个 JavaFX 应用程序。
See Working With JavaFX Samples for samples from which you can learn more about the JavaFX Script language and theLearning More About JavaFX page for additional resources.
This section guides application developers in creating their first JavaFX application by using the NetBeans IDE 6.5 for JavaFX 1.0technology. For web designers who want to get started using the JavaFX1.0 Production Suite, see the Getting Started With JavaFX 1.0 Production Suite article.
这一章指导应用开发人员使用NetBeans IDE 6.5 for JavaFC 1.0 技术来创建第一个 Java FX 应用.对于想使用JavaFX 1.0 Production Suite 的 Web 设计人员,看这个文章 Getting Started With JavaFX 1.0 Production Suite 。
In this section, you create a simple sphere with text that changes color and performs a scaling transformation within a specified timeperiod, as shown next:
这一章,你要创建一个简单的球体。包含可以改变颜色和执行一个指定时间周期的平滑变化的文字,如下所示:
JAVA世纪网 http://www.java2000.net
Figure 1: Finished JavaFX Sphere
完成的JavaF 球体
1. Ensure that you have the NetBeans IDE 6.5 for JavaFX 1.0 software already installed on your system. If necessary, revisit the What to Download page.
确信你已经安装了NetBeans IDE 6.5 for JavaFX 1.0 软件。
2. Start the NetBeans IDE.
启动 NetBeans IDE
a. For Windows. Choose Start > All Programs > NetBeans > NetBeans IDE 6.5
在Windwos 平台,选择 Start > All Programs > NetBeans > NetBeans IDE 6.5
b. For Mac OS X. Select Applications > NetBeans > NetBeans 6.5
在 MAC OS上,选择 Applications > NetBeans > NetBeans 6.5
3. Create a JavaFX Script Application project.
创建 JavaFC Script 应用项目
a. Choose File > New Project (Ctrl-Shift-N).
选择 File > New Project (Ctrl-Shift-N).
b. Inthe New Project wizard, select JavaFX in the Categories pane and JavaFXScript Application in the Projects pane. Click Next.
在新建项目向导里,在分类面板里面选择 JavaFX,在 项目面板里选择 JavaFXScript 应用,点击[Next]
c. On the Name and Location page, type FirstJavaFXSpherefor the Project Name, specify your desired location for the project's files in the Project Location text field, and leave all other default values unchanged, as shown in Figure 2.
在名字和位置页面,输入[FirstJavaFXSphere]作为项目的名字,指定项目文件的路径,其它的保持默认值不要改变,如图2所示:
Figure 2: New Project Wizard With Project Name and Location Specified.
图2,新建项目向导,项目名称和指定位置 JAVA世纪网 http://www.java2000.net
d. Click Finish.
点击[Finish]
The FirstJavaFXSphere project opens in both the Projects window and the Files window, and the Main.fx file opens in the source editor, as shown in Figure 3.
项目同时在项目窗口和文件窗口打开,Main.fx 被源代码编辑器打开,如图3所示:
Figure 3: FirstJavaFXSphere Project Opened in Projects Window and Main.fx File in the Source Editor.
Notice that JavaFX Script code is included within the Main.fx file by default. This code includes several import statements and object literals (like Stage). These Object literals represent key concepts within a JavaFX application, and are described in the table below.
注意:JavaFX的脚本代码是默认包含在Main.fx 文件里的。代码包含了一些import语句和对象文字。这些对象表示JavaFX里买你的关键概念,将在下面的表格里描述 JAVA世纪网 http://www.java2000.net
Table 1: Object Literals Created by Default
Object Literal | Description |
Stage | The
top level container window required to display any visible JavaFX
objects. The default instance variables title, width and height define
the the text that appears on the window's top border and its height and
width. The scene variable defines an instance of the Sceneobject
literal, which sets the area in which you can place the JavaFXobjects.
最顶部的窗口容器,用来显示所有可见的JavaFX对象。默认的实例变量 title,width和height分别定义了出现在窗口顶部边框里的的文字(标题)和窗口的高度和宽度。 |
Scene | This is similar to a drawing
surface for the graphical content of your application. The scene
instance variable has a content variable that is used to hold JavaFX
graphical elements and defines the graphical content of your
application. For more information about theScene class, see Presenting UI Objects in a Graphical Scene, a lesson in Building GUI Applications With JavaFX
这个类似于你应用程序的图形内容的画布。场景实例变量包含一个内容变量,拥有了JavaFX图形元素,并定义了你应用程序的图形内容。 |
Text | Defines the graphical element that displays text in the scene.
定义了场景里显示的文字图形元素 |
Font | Defines the font used to display the text in the scene.
定义场景里用来显示文字的字体 |
4. Modify the Stage object, as shown next, so that the window has the title, window size,and text that we want to appear in the application we are building. You also need to add the import statement for the TextAlignment class.
如后面所示,修改场景对象,来让窗口有便同意,窗口尺寸和我们想创建应用要显示的文字。你同样需要增加import语句给TextAlignment 类。
a.Modify the Stage object literal as shown below. You may copy the lines in bold and paste them in the editor.
修改Stage 对象Source Code
源代码
引用:
Stage {
title: "My First JavaFX Sphere"
width: 250
height: 250
scene: Scene {
content: [
Text {
font: Font { size: 24 }
x: 20, y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
} //Text
] // content
} // Scene
} // Stage
b. To fix the highlighted error due to a missing import statement for the TextAlignment class used, right-click in any white space in the editor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的 TextAlignment 类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I)
The following import statement is added to the top of the Main.fx file.Source Code
import 语句被叫如到Main.fx源代码的最顶部 JAVA世纪网 http://www.java2000.net
引用:
import javafx.scene.text.TextAlignment;
5. Define the basic Circle object from which you create the sphere by expanding the Basic Shapes section in the Palette window and dragging the Circle code snippet in the line above the Text code block, as shown next.
从Pallette 窗口拖动 Circle 代码片段来创建球星的基础。
Figure 4: Drag the Circle Code Snippet From the Palette Window.
6. Modify the circle's instance variables so that it has the correct size to contain the text. Also, add a new RadialGradient setting, which makes the circle have a little depth and look more like a sphere.Modifythe source file with the following source code in bold. You can copy the lines in bold, including the closing square and curly braces forthe fill variable, and paste them to the source editor.
修改圆的实例属性到正确的尺寸和文字。同时增加一个 RadialGradient 配置,来让圆看上去有一些深度,更像一个球。如下的粗体部分修改源代码。 JAVA世纪网 http://www.java2000.net
Source Code
引用:
Stage {
title: "My First JavaFX Sphere"
width: 250
height: 250
scene: Scene {
content: [
Circle {
centerX: 100,
centerY: 100
radius: 90
fill: RadialGradient {
centerX: 75
centerY: 75
radius: 90
proportional: false
stops: [
Stop {
offset: 0.0
color: Color.RED},
Stop {
offset: 1.0
color: Color.DARKRED}
] // stops
} // RadialGradient
} // Circle
Text {
font: Font {
size: 24
}
x: 20, y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
} //Text
] // content
} // Scene
} // Stage
b. To fix the errorsthat are highlighted because of the missing import statements forseveral classes introduced in the previous step, right-click in anywhite space in the editor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的 一些类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I) JAVA世纪网 http://www.java2000.net
The following import statements are added to the top of the Main.fx file.
如下的import 语句被加入到Main.fx文件的顶部
Source Code
引用:
import javafx.scene.paint.RadialGradient;
import javafx.scene.paint.Stop;
7. Turn on the Preview feature by clicking the Enable Preview button on the editor toolbar.
点击编辑按扭栏的【 Enable Preview 】按钮来打开预览特性
A new Design Preview window displays the circle you just modified to look more like a sphere, as shown next. The preview feature enables you to view the current state of the GUI design you are creating. As you modify the source code and if no errors are encountered, the design preview window displays the current status of the GUI you are building.
一个设计预览窗口打开,显示你刚才修改的圆看上去更像一个球。预览特性让你可以查看当前GUI设计的状态。当你修改了源代码且没有代码错误,设计预览窗口将显示你当前建立的GUI状态。
Figure 5: Sphere in Designer Preview Window.
8. Use the following steps to change the color of the text to yellow and to add a drop shadow effect.
使用下面的步骤来修改文字颜色为黄色,同时增加一个阴影效果。
a.Add the variables color and scale with their initial default values set.
增加颜色和比例变量以及初始值。
These variables will be used in the timeline animation you will create in later steps.
这些只用与后面步骤的时间线的动画
Source Code
引用:
var scale = 1.0;
var color = Color.YELLOW;
Stage {
title: "My First JavaFX Sphere"
width: 250
height: 250
b.Modify the Text object so that the lines defining the fill, effect, and transforms variable instances are added, as shown in bold below. You may copy the lines in bold below and paste it to the source editor.
修改文本对象来定义填充效果和增加转换变量实例。 JAVA世纪网 http://www.java2000.net
Source Code
引用:
Text {
font: Font {
size: 24
}
x: 20,
y: 90
textAlignment: TextAlignment.CENTER
content:"Welcome to \nJavaFX World"
fill: bind color
effect: DropShadow {
offsetX: 10
offsetY:10
color: Color.color(0.1, 0.3, 0.1)
}; // DropShadow
transforms: Scale{
x: 1
y: bind scale
pivotX: 100,
pivotY: 100
} // Scale
} // Text
The fill variable instance binds the Text's color to the variable color. A drop shadow effect is added and the scaling transformation is defined. The transforms variable defines the value of the Scale object returned from the call to the Scale function. The Scale object represents a scaling transformation defined by the specified variables, x, y, pivotX, and pivotY. The x and y variables define the factor by which coordinates are scaled along the x and y axis directions. The pivotX and pivotY variables define the X and Y coordinates about which point the scale occurs.
填充变量实例绑定了文本的颜色为变量的颜色。增加影响效果和定义缩放变换。变换变量定义了缩放的对象调用缩放功能返回的对象。缩放对象 通过缩放的变换变量 x,y,provotX和 provotY定义。 x和y变量定义了沿着x和y坐标缩放的比例参数。 privotX和privotY变量定义了发生缩放的点的X和Y坐标。
To correct the highlighted errors due to the missing import statements forthe two classes introduced, right-click in any white space in theeditor and select Fix Imports (Ctrl+Shift+I).
为了修正高亮的缺少 import 语句的2个类的错误信息,你可以在编辑器的任何空白地方右键,选择 Fix Imports (Ctrl+Shift+I)
Select the javafx.scene.effect.DropShadow in the first dialog, as shown in Figure 6, and press Enter. In the next pop-up dialog, select the javafx.scene.transform.Scale and press Enter.
在第一个对话框里选择 javafx.scene.effect.DropShadow,按回车,在下一个弹出对话框里选择 javafx.scene.transform.Scale然后回车。 JAVA世纪网 http://www.java2000.net
Figure 6: Fix Imports pop-up dialog.
The following import statement is added to the top of the Main.fx file.
下面的import语句被加入到Main.fx文件的顶部
Source Code
引用:
import javafx.scene.effect.DropShadow;
import javafx.scene.transform.Scale;
Notice in the Design Preview window that the text's color has changed to yellow and the drop shadow effect now appears, as shown next.
注意设计预览窗口的文字颜色已经变成黄色,阴影效果也出现了。
Figure 7: Sphere Updated in the Designer Preview Window.
9. Add animation by having the text change from yellow to green and have it rotate.
增加文字从黄色到绿色的动画效果,然后循环
a. Expand the Animation section in the Palette window, select Timeline, and drag the Timeline code snippet to the line just above the Stage code block, as shown next.
打开 Pallette 窗口的 Animation 区,选择 Timeline(时间线),拖动Timeline 代码片段到刚好在Stage代码块的上面。
Figure 8: Drag Timeline Code Snippet from the Palette to the Source Editor.
Animation occurs along a timeline, represented by a javafx.animation.Timeline object. Each timeline contains one or more key frames, represented by javafx.animation.KeyFrame objects.For more information about animation, see Creating Animated Objects, a lesson in Building GUI Applications With JavaFX.
动画沿着时间线发生,通过 javafx.animation.Timeline对象实现。每个时间线包含一个或多个关键帧,通过 javafx.animation.KeyFrame 对象表示。
b. Change the value of the time instance variable from 1s to 5s so that now the Timeline object literal is as shown below.
修改时间实例的值,从1s 到 5s, 如下所示 JAVA世纪网 http://www.java2000.net
Source Code
引用:
Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames : [
KeyFrame {
time : 5s
canSkip: true
} // KeyFrame
] // keyFrames
} // Timeline
This timeline repeats indefinitely on a five second interval. The value of the time instance variable, 5 seconds, defines the elapsed time at which the values within the key frame will be set in a single cycle of the Timeline object. The next couple of steps of this tutorial define those values to be set.
时间线每5秒无限重复。 实例的 time 变量为5秒,表示Timeline 对象在一个循环里关键帧里要消耗的时间。这个向导的后面的步骤定义了这些变量。
c. Drag the Animation > Values code snippet from the Palette to the line just after time variable.
拖动 Animation > Values 代码片段从 Pallette 到 time 变量的后面
Figure 9: Drag Values Code Snippet from the Palette to the Source Editor.
Values define the list of target variables and the desired values they should interpolate at the specified time of the KeyFrame.
变量Values定义了一系列目标变量和KeyFrame希望插入使用的变量。
d. Copy the lines shown in bold below and paste it to the source editor to modify the values instance. The added code changes the text's color from yellow to green as it eases.
复制后面的粗体部分代码,粘贴到你的代码里面。 JAVA世纪网 http://www.java2000.net
Source Code
引用:
values : [
scale => -1.0 tween Interpolator.EASEBOTH
[b]color => Color.GREEN
] // values[/b]
The desired values of the scale and color variables are defined within the 5 seconds interval of the keyframe. The =>operator provides a literal constructor (a special notation) that makesit easier to express the list of key interpolated values or object properties.
要使用的缩放和颜色变量被定义在关键帧的5秒周期内。 => 操作符提供了一个结构,来简单的描述一系列的关键插入值和对象属性。
In this case, we use the tween operator to construct the interpolated values for the scale between 1.0 and -1.0 to create the illusion of rotation. The Interpolator.EASEBOTH is the built-in interpolator instance that provides for ease in and out behavior. Also, over the same 5 second period, the color of the text will change from yellow to green.
在这个情况下,我们使用 tween 操作符来构建一个内插的数值,从1.0到 -1.0 来创建一个旋转的现象。Interpolator.EASEBOTH 是内建的内插实例,来提供擦除内部和外部的功能。同样,在5秒的周期内,文本的颜色将从黄色变成绿色。 JAVA世纪网 http://www.java2000.net
Right-click in any white space in the editor and select Format (Alt+Shift+F) to properly align the newly added lines of code.Add .play(); to the end of the Timeline object declaration, as shown below in bold.
在任何编辑的空白地方点右键,选择 Format (Alt+Shift+F) 来让新增加的代码行正确对齐。在Timeline对象的末尾增加 .play()
The play() method plays the timeline as defined. The completed Timeline object should be as shown next.
play方法运行定义的时间线。完整的Timeline对象如下
Source Code
引用:
Timeline {
repeatCount: Timeline.INDEFINITE
keyFrames: [
KeyFrame {
time: 5s
canSkip: true
values : [
scale => -1.0 tween Interpolator.EASEBOTH
color => Color.GREEN
] // values
} // KeyFrame
] // keyFrames
}.play();
Notice in the Design Preview window that the text's color is now continuously changing from yellow to green as it appears to rotate. Ifyou are not seeing this, click the Reset Preview button.
注意,设计预览窗口里,文字颜色将布点的从黄色变到绿色,并且循环。如果你没有看到这个,那么点一下Reset Preview 按钮。
10. Run the project.
运行项目
Close the Design Preview window.In the Projects window, right-click the FirstJavaFXSphere project node and select Run Project.
关闭设计预览窗口,在项目窗口,右键点击 FirstJavaFXSphere 项目节点,选择 Run Project.
The IDE compiles the project and prepares the files necessary to run the application using the Desktop execution model. When the project is compiled successfully, an animated sphere similar to what is shown in Figure 1 is displayed. The color of the text should change from yellow to green as it appears to rotate.
IDE编译项目,准备桌面运行模式运行需要的文件。当项目编译成功后,一个模拟的球形动画将显示如图一所示。文本的颜色将从黄色变到绿色,并循环显示。 JAVA世纪网 http://www.java2000.net
Congratulations! You've just created your first JavaFX application.
祝贺你,你已经创建了你第一个 JavaFX 应用程序。
See Working With JavaFX Samples for samples from which you can learn more about the JavaFX Script language and theLearning More About JavaFX page for additional resources.
相关推荐
在"javaFx 学习--入门示例程序的源码"这个压缩包中,包含了一个名为"helloworld"的文件,这通常是一个初学者接触任何编程语言或库时的第一个示例。 HelloWorld 示例是编程领域的基础,它演示了如何在JavaFX中展示...
JavaFX Script为创建富互联网客户端应用程序提供了一种新的途径。通过本书的学习,读者不仅能够掌握JavaFX Script的基本知识和技能,还能深入了解如何利用这一强大工具来构建高质量、跨平台的应用程序。无论是对于...
- 创建第一个JavaFX应用程序的步骤。 - 基础组件与布局管理器的介绍。 #### 第2章:Creating a User Interface in JavaFX - **目标读者**:希望掌握如何构建用户界面的开发者。 - **内容概览**: - 使用JavaFX ...
1. **第一章:JavaFX 入门**(Introduction to JavaFX) - 介绍 JavaFX 的基本概念及其在富客户端应用开发中的作用。 - 解释 JavaFX Script 如何与其他 JavaFX 技术组件协同工作。 2. **第二章:快速入门**...
- 演示如何创建第一个 JavaFX 应用程序。 - 解释 JavaFX 的架构和工作原理。 - **第 2 章:基本组件与布局** - 讨论 JavaFX 中的基本 UI 组件,如按钮、文本框等。 - 介绍不同类型的布局容器,如 HBox、VBox 和 ...
1. **第一章:快速入门 JavaFX** - **目的**:介绍 JavaFX 的历史背景以及如何获取 JavaFX SDK。 - **主要内容**: - JavaFX 的发展历史。 - 如何下载和安装 JavaFX SDK。 - JavaFX 相关资源的探索。 - 通过...
### JavaFX入门教程知识点详解 #### 一、JavaFX简介 **JavaFX** 是由Sun Microsystems(现已被Oracle收购)开发的一种高级编程语言和技术平台,主要用于构建丰富的客户端应用程序。JavaFX的目标是简化开发者的工作...
- **定义与目标**:JavaFX 平台是 Java 客户端设计演进的一个里程碑,旨在让应用开发者能够轻松地创建和部署跨平台且表现一致的 Rich Internet Applications (RIA)。 - **技术核心**:JavaFX 是基于 Java 技术构建的...
在编写第一个脚本时,需要了解编译源代码、运行应用程序、声明脚本变量、定义和调用脚本函数、向脚本函数传递参数以及访问命令行参数。这些知识点将在编写一个简单的计算器应用程序时被介绍。 knowledge point 5: ...
读者将学会如何设置开发环境并运行第一个 JavaFX 应用程序。 ##### 第 2 章:属性与绑定 属性和绑定是 JavaFX 中非常重要的特性之一。通过学习本章,读者可以掌握如何使用 JavaFX 的属性系统来创建响应式 UI 组件,...
有任何使用问题欢迎随时与博主沟通,第一时间进行解答!该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 基于STM32、ESP8266、PHP、QT、应用软件开发、系统...
- **第1章:JavaFX入门** - 本章首先回顾了JavaFX的历史背景及其在Sun Microsystems宣布推出时所设定的目标,即在各种消费设备(如手机、电视、车载系统等)上部署内容丰富的应用程序。 - 讨论了JavaFX如何简化和...
JavaFX 是一款由 Sun Microsystems 开发并由 Oracle 继续维护的跨平台用户界面工具包,旨在为开发者提供一种创建丰富、动态且交互性强的应用程序的方式。在2007年的 JavaOne 大会上,Sun 首次公布了 JavaFX 的概念,...
2. **JavaFX 9**:是JavaFX平台的第九个主要版本,提供了许多新特性和改进,使开发者能够创建更加现代化和功能丰富的桌面应用程序。 3. **实例学习(Example-based learning)**:通过阅读和分析代码实例,读者能够...
JavaFX 2.0是Java平台下一代图形用户界面(GUI)工具包,为开发者提供了一个强大的框架来快速构建功能丰富、视觉效果出色的跨平台应用程序。与之前的版本相比,JavaFX 2.0进行了重大改进,包括硬件加速图形渲染、更...
JavaFX的目标是提供一个更简洁、优雅的方式来创建内容丰富的应用程序,尤其是在移动设备如手机、电视、车载系统以及浏览器等消费者设备上。 JavaFX的设计理念旨在解决传统Java GUI框架如Swing和Java 2D中存在的复杂...
本书《Pro Java FX 2》旨在为开发者提供一个全面而深入的学习路径,帮助他们掌握使用JavaFX开发富客户端应用程序的技术。JavaFX是一个由Oracle公司维护的软件平台,用于构建桌面应用以及网页应用。本书通过一系列...
这一章将带你进入图形用户界面(GUI)的构建,使用Java的Swing库或JavaFX来创建交互式应用程序。你会学习如何创建窗口、按钮、文本框等组件,以及布局管理器来组织这些组件。事件处理机制也是这一章的重点,让你的...