0137013531.pdf by Unknown

0137013531.pdf by Unknown

Author:Unknown
Language: eng
Format: epub


SETTING UP NETBEANS IDE FOR JAVAFX 1.2

3

Figure 1.1

New JavaFX Project

ptg

Figure 1.2

New JavaFX Project – Name and Location

From the Library of sam kaplan

4

CHAPTER 1

GETTING STARTED

ptg

Figure 1.3

New JavaFX Project – Main.fx Editor Window

Create Main File checkbox checked when you created the project. Use this file to create your simple first application. Figure 1.3 shows the editor window for the Main.fx source file.

The Main.fx file will have skeleton code that displays a window with some text.

You need to modify this code. Like all good “Getting Started” chapters, let’s do the proverbial Hello World example. We’ll cover the details later, but the code in Listing 1.1 will show a window on the desktop, with “Hello World” displayed.

Listing 1.1

Simple Hello World Application

package myfirstjavafxapplication;

import javafx.stage.Stage;

import javafx.scene.Scene;

import javafx.scene.text.Text;

From the Library of sam kaplan

SETTING UP NETBEANS IDE FOR JAVAFX 1.2

5

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 ptg

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, compile, 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.

From the Library of sam kaplan



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.