Java Reference
In-Depth Information
import javafx.scene.text.Font;
Stage {
title: "My first JavaFX Application"
width: 400
height: 80
scene: Scene {
content: Text {
font : Font {
size : 24
}
x: 10, y: 30
content: "Hello World"
}
}
}
To view the resulting screen while editing the file, use the JavaFX Preview
mode. To enter the preview mode, click on the Preview icon at the top left of the
Main.fx editor (see Figure 1.4). This opens a new window on top of the Main.fx
editor window and lets you see what the screen will look like as you type in your
changes. Figure 1.4 shows the preview window.
For example, let's change your application to scale Hello World by a factor of 4.
This is done by using the scaleX and scaleY attributes for the Text element.
These attributes will cause the Text to scale 4 times anchored from its center
point. Figure 1.5 shows the changes instantly in the preview window.
By using Preview mode, you can quickly see the impact of your changes. It
allows you to test new effects out without having to cycle through the edit, com-
pile, run loop for each iteration of changes. As soon as you type the change, the
screen updates with the latest view.
Hello World is kind of boring, so let's have some fun and spice it up. We'll add a
gradient background, make the font bigger, and add a reflection effect. Using the
original example for Hello World, you add the code to get your desired effect.
You will learn what each part of this new code does in later chapters, but for now
we want to show you what is possible. Figure 1.6 shows this far more interesting
Hello World example.
Listing 1.2 shows how this was done. It is actually quite simple and concise.
That is the beauty of the JavaFX Platform.
Search WWH ::




Custom Search