- 浏览: 1464042 次
- 性别:
- 来自: 北京
-
最新评论
-
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

点击编辑按扭栏的【 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

注意,设计预览窗口里,文字颜色将布点的从黄色变到绿色,并且循环。如果你没有看到这个,那么点一下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.
相关推荐
基于Python的天气预测与可视化(完整源码+说明文档+数据),个人经导师指导并认可通过的高分设计项目,评审分99分,代码完整确保可以运行,小白也可以亲自搞定,主要针对计算机相关专业的正在做大作业的学生和需要项目实战练习的学习者,可作为毕业设计、课程设计、期末大作业,代码资料完整,下载可用。 基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基于Python的天气预测与可视化(完整源码+说明文档+数据)基
内容概要:本文详细介绍了利用MIM(金属-介质-金属)结构进行梯度相位超表面的设计与仿真的全过程。首先,通过Au-MgF2-Au三明治结构,利用磁偶极子共振实现高效的相位控制。接着,通过FDTD仿真工具,编写参数扫描脚本来优化纳米柱尺寸,从而实现广泛的相位覆盖。然后,通过近远场变换计算异常反射效率,验证了高达85%以上的反射效率。此外,还探讨了宽带性能验证的方法以及梯度相位阵列的设计思路。最后,提供了实用的代码片段和注意事项,帮助读者理解和复现实验结果。 适合人群:从事超表面研究、光束控制、电磁仿真领域的科研人员和技术开发者。 使用场景及目标:适用于希望深入了解MIM结构在超表面设计中的应用,掌握FDTD仿真技巧,以及探索高效光束偏折机制的研究人员。目标是通过详细的步骤指导,使读者能够成功复现并优化类似实验。 其他说明:文章不仅提供了理论背景,还包括大量具体的代码实现和实践经验分享,有助于读者更好地理解和应用所学知识。
内容概要:本文探讨了利用主从博弈理论解决共享储能与综合能源微网之间的利益冲突。通过MATLAB和YALMIP+Cplex工具,构建了微网运营商、用户聚合商和共享储能服务商三者之间的博弈模型。主要内容包括系统架构介绍、核心代码解析、求解策略以及仿真结果分析。文中详细展示了如何通过Stackelberg模型实现三方利益的最大化,并提供了完整的代码实现和详细的注释。 适合人群:从事能源互联网项目的研发人员、对博弈论及其应用感兴趣的学者和技术爱好者。 使用场景及目标:适用于希望深入了解能源系统优化、主从博弈理论及其MATLAB实现的研究人员和工程师。目标是掌握如何通过编程手段解决复杂系统中的多主体利益协调问题。 其他说明:文章不仅介绍了理论背景,还提供了具体的代码实现细节,如参数初始化、目标函数构建、约束条件处理等。此外,还包括了仿真结果的可视化展示,帮助读者更好地理解模型的实际效果。
内容概要:本文深入探讨了基于FPGA平台实现直方图统计与均衡化的全过程,涵盖直方图统计、累积直方图计算和均衡化处理三大核心步骤。文中不仅提供了详细的Verilog代码实现,还介绍了关键的设计思路和技术难点,如双端口BRAM的应用、流水线控制、除法器资源优化等。此外,通过Matlab代码进行了结果验证,确保FPGA实现的准确性。 适合人群:从事FPGA开发、图像处理、计算机视觉等相关领域的工程师和技术爱好者。 使用场景及目标:适用于需要高性能、低延迟图像处理的应用场景,如实时视频处理、医学图像处理、卫星图像增强等。目标是掌握FPGA实现直方图均衡化的技术细节,提高图像对比度和清晰度。 其他说明:文章强调了FPGA相较于CPU和GPU在并行处理和硬件加速方面的优势,并提供了丰富的代码实例和测试结果,帮助读者更好地理解和应用这一技术。
内容概要:本文详细介绍了利用LSTM模型进行高速公路车辆换道轨迹预测的研究过程。首先,作者使用来自I-80和US-101高速公路的实际换道轨迹数据,这些数据包括横向和纵向的速度、加速度以及轨迹坐标等特征。通过对数据进行预处理,如标准化、划分训练集和测试集等步骤,确保了数据的质量。然后,设计并实现了包含两层LSTM和一层全连接层的神经网络模型,采用Adam优化器进行训练,并通过交叉熵损失函数评估模型性能。实验结果显示,模型在测试集上的准确率达到85%,表明LSTM模型能够有效捕捉车辆换道的行为模式。 适合人群:从事自动驾驶技术研发的专业人士,尤其是对深度学习应用于交通预测感兴趣的工程师和技术研究人员。 使用场景及目标:本研究旨在提高自动驾驶系统的安全性与效率,具体应用场景包括但不限于城市快速路、高速公路等复杂路况下车辆换道行为的提前预测,从而辅助驾驶员或自动驾驶系统做出更好的决策。 其他说明:尽管目前模型已经取得了较好的成绩,但仍存在改进空间,例如可以通过引入更多类型的传感器数据(如摄像头图像)、优化现有模型结构等方式进一步提升预测精度。此外,考虑到实际应用中的实时性和鲁棒性要求,后续还需针对硬件平台进行针对性优化。
个人资料-111相关内容
内容概要:本文详细介绍了使用HyperWorks和LS-DYNA进行汽车碰撞仿真的方法和技术要点。从网格划分、材料属性设置、连接装配到最后的分析计算和结果处理,每个环节都配有具体的代码示例和注意事项。文中不仅涵盖了正碰、侧碰、偏置碰等多种类型的碰撞分析,还包括了座椅安全带约束等特殊部件的建模技巧。此外,作者分享了许多实践经验,如网格尺寸的选择、材料参数的设定以及求解器设置的最佳实践,帮助读者避免常见的陷阱并提高仿真效率。 适合人群:从事汽车工程领域的工程师、研究人员以及对汽车碰撞仿真感兴趣的初学者。 使用场景及目标:适用于需要掌握汽车碰撞仿真完整流程的专业人士,旨在提升其在实际项目中的应用能力,确保仿真结果的准确性和可靠性。 其他说明:附赠的源代码进一步增强了学习效果,使读者能够快速上手并在实践中不断优化自己的技能。
内容概要:本文详细介绍了如何在MATLAB/Simulink环境中搭建四分之一车被动悬架双质量(二自由度)模型。该模型主要用于研究车辆悬架系统在垂直方向上的动态特性,特别是面对路面不平度时的表现。文中不仅提供了具体的建模步骤,包括输入模块、模型主体搭建和输出模块的设计,还给出了详细的参数配置方法和仿真分析技巧。此外,文章还探讨了如何通过调整悬架系统的参数(如阻尼系数)来优化车辆的乘坐舒适性和行驶安全性。 适合人群:从事汽车动力学研究的专业人士、高校相关专业的学生以及对车辆悬架系统感兴趣的工程师。 使用场景及目标:①用于教学目的,帮助学生理解车辆悬架系统的理论知识;②用于科研实验,验证不同的悬架设计方案;③为企业产品研发提供技术支持,改进现有产品的性能。 其他说明:文中提供的代码片段和建模思路有助于读者快速上手并掌握Simulink建模技能。同时,强调了实际应用中的注意事项,如选择合适的求解器、处理代数环等问题。
内容概要:本文详细介绍了使用MATLAB进行语音数据处理的完整流程,涵盖从音频文件读取、特征提取(特别是梅尔倒谱系数MFCC)、分类器构建(支持向量机SVM)到最后的性能评估(混淆矩阵)。作者分享了许多实用技巧,如避免常见错误、优化特征提取参数以及提高分类准确性的方法。文中提供了大量具体代码示例,帮助读者快速理解和应用相关技术。 适合人群:对语音信号处理感兴趣的初学者或有一定经验的研究人员和技术爱好者。 使用场景及目标:适用于希望深入了解语音识别系统内部机制的人群,尤其是希望通过MATLAB平台实现简单而有效的语音分类任务的学习者。主要目的是掌握如何利用MATLAB工具箱完成从原始音频到分类结果可视化的全过程。 其他说明:除了介绍基本概念外,还强调了一些实践经验,例如预处理步骤的重要性、选择合适的滤波器数目、尝试不同的分类器配置等。此外,作者鼓励读者根据实际情况调整参数设置,以获得更好的实验效果。
基于python+yolov5和deepsort实现的行人或车辆跟踪计数系统+源码+项目文档+演示视频,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 项目运行环境:win10,pycharm,python3.6+ 主要需要的包:pytorch >= 1.7.0,opencv 运行main.py即可开始追踪检测,可以在控制台运行 基于python+yolov5和deepsort实现的行人或车辆跟踪计数系统+源码+项目文档+演示视频,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用,详情见md文档 项目运行环境:win10,pycharm,python3.6+ 主要需要的包:pytorch >= 1.7.0,opencv 运行main.py即可开始追踪检测,可以在控制台运行~
内容概要:本文详细介绍了金-氟化镁-金(MIM)结构在超表面全息领域的应用及其高效性能。首先探讨了MIM结构中磁偶极子模式的优势,特别是其低辐射损耗的特点。接着讨论了几何相位的应用,展示了纳米柱旋转角度与相位延迟之间的线性关系,并解决了相位误差的问题。随后介绍了改进的GS算法,提高了迭代收敛速度。最后,通过FDTD仿真验证了MIM结构的高效率,提供了详细的仿真参数设置和优化技巧。 适合人群:从事超表面研究、光学工程、纳米技术和FDTD仿真的研究人员和技术人员。 使用场景及目标:适用于希望深入了解MIM结构在超表面全息中的应用,以及希望通过FDTD仿真进行相关研究的专业人士。目标是提高超表面全息的转换效率,探索新的应用场景如涡旋光生成和偏振加密全息。 其他说明:文中提供了大量具体的代码片段和参数设置,帮助读者更好地理解和复现实验结果。此外,还提到了一些常见的仿真陷阱和解决方案,有助于避免常见错误并提升仿真准确性。
内容概要:文章介绍了金融科技公司信用飞如何通过关注用户信用成长,利用先进技术和专业服务为用户量身定制金融解决方案,从而实现用户资产的稳健增值。首先,信用飞通过多维度数据分析,全面了解用户的信用状况和需求,为不同信用水平的用户提供个性化服务。其次,建立了动态信用评估体系,实时监测并调整用户信用服务策略,帮助用户持续提升信用。再者,根据不同用户的需求,提供包括信用消费、理财投资、融资借贷等在内的多样化金融服务。最后,借助大数据、人工智能、区块链等技术手段,确保金融服务的安全可靠和高效便捷,持续陪伴用户实现信用与财富的双重增长。 适合人群:对个人信用管理有一定需求,希望通过科学金融规划实现资产稳健增值的个人及小微企业主。 使用场景及目标:①希望提升个人或企业信用评级的用户;②寻求合适金融产品和服务以优化财务管理的人群;③需要安全可靠的融资渠道支持业务发展的创业者和中小企业。 阅读建议:本文详细阐述了信用飞如何通过技术创新和个性化服务助力用户信用成长及资产增值,建议读者重点关注文中提到的技术应用和服务特色,结合自身情况思考如何更好地利用此类金融科技服务来优化个人或企业的财务状况。
少儿编程scratch项目源代码文件案例素材-AI战争.zip
内容概要:本文详细介绍了出口设备1200线体程序的配置与优化方法,涵盖PLC通讯控制、V90模块配置以及工艺对象与FB284的协同控制。文章强调了开源特性的优势,使得用户可以自由扩展和优化控制系统。主要内容包括:1) 出口设备1200线体程序的核心地位及其复杂控制逻辑;2) 多个PLC设备的通讯协作,确保数据可靠传输;3) V90模块的具体配置步骤,确保各模块稳定运行;4) 工艺对象与FB284的协同控制,避免逻辑冲突;5) 开源带来的便利性,便于用户进行功能扩展和学习;6) 实际应用中的优化措施,提高系统的运行效率。 适合人群:从事工业自动化领域的工程师和技术人员,尤其是那些希望深入了解PLC通讯控制和V90伺服配置的人。 使用场景及目标:适用于需要配置和优化出口设备1200线体程序的实际工程项目,帮助用户掌握PLC通讯、V90配置及工艺对象与FB284协同控制的方法,从而提升生产线的效率和稳定性。 其他说明:文章提供了大量实用的代码片段和调试技巧,有助于读者更好地理解和实施相关配置。同时,文中提到的一些具体案例和经验分享也为实际操作提供了宝贵的参考。
前端面试与vue源码讲解
少儿编程scratch项目源代码文件案例素材-green vs blue.zip
内容概要:本文详细介绍了博世汽车电驱仿真模型中同步电机和异步电机的FOC(磁场定向控制)技术及其优化方法。主要内容涵盖相电流波形生成、弱磁控制、正反转切换、滑差补偿以及铁损计算等方面的技术细节。通过MATLAB、Python和C等多种编程语言实现了对电机控制的精确模拟,展示了如何通过数学方法和智能算法提高电机性能,减少电流畸变和转矩脉动。文中特别强调了弱磁控制在高速区的应用,通过动态查表法自动调整d轴电流分量,有效解决了电压极限椭圆的问题。此外,还提到了一些创新性的技术应用,如相位预判机制、动态滑差补偿和自适应耦合系数计算等。 适合人群:从事电机控制、电动汽车研究及相关领域的工程师和技术人员。 使用场景及目标:适用于希望深入了解同步电机和异步电机FOC控制原理及其实现方法的研究人员和工程师。目标是掌握先进的电机控制技术和优化方法,应用于实际项目中,提高系统性能和可靠性。 其他说明:文章不仅提供了详细的理论解释,还附有具体的代码实现,便于读者理解和实践。同时,文中提到的一些创新性技术可以为相关领域的研究提供新的思路和方法。
少儿编程scratch项目源代码文件案例素材-RPG游戏引擎5.5c.zip
2025年6G近场技术白皮书2.0.pdf
少儿编程scratch项目源代码文件案例素材-scratch 通关游戏.zip