28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 5 ■ An Introduction to Game Design: Concepts, Multimedia, and Using Scene Builder<br />

Next, let’s take a look at FXML markup language specifically, at an in-depth level. After that, you will examine an<br />

actual FXML UI definition structure, and you will see exactly how the current <strong>Java</strong>FX application’s UI design would be<br />

structured using an FXML UI definition construct. As you will see, FXML makes UI design a lot easier!<br />

FXML Definition: Anatomy of an XML UI Definition Construct<br />

The FXML structure is based on the <strong>Java</strong>FX classes (objects), and their attributes, that the FXML tags, and parameters<br />

structures, which you can easily create, allow you to “mock up” a front-end UI more easily, using a mark-up language.<br />

The FXML structure lets you more easily construct your Scene Graph hierarchy, and the FXML tags and their<br />

parameters, which you will be looking at in the next section, match up 1:1 with the <strong>Java</strong>FX API classes.<br />

Once you create your UI design, the <strong>Java</strong> programmers can use javafx.fxml classes and methods to inflate<br />

your UI layout container and UI control arrangement into a <strong>Java</strong>FX scene and Scene Graph structure, based on <strong>Java</strong><br />

objects. Then, the UI design can be used in the application <strong>Java</strong> code. As mentioned earlier, FXML is most useful for<br />

designing complex, static (fixed) UI design layouts containing lots of buttons, forms, check boxes and the like.<br />

Hello World UI FXML Definition: Replicating Your Current UI Design,<br />

Using FXML<br />

The first thing that you define in the FXML structure is the FXML processing instructions. Each processing<br />

instruction starts with a less-than sign, question mark sequence (]). The first processing instruction is a declaration of the XML language<br />

use, its version (1.0), and the text character set language-encoding format that you want to use (in this case,<br />

UTF-8 [universal character set transformation format, 8 bit]). Because it is 8 bit, there are 256 characters in this<br />

international character set, which was designed to span the many languages based on Germanic characters, that is,<br />

languages that use an A to Z alphabet (including accented characters).<br />

Following the declaration of an XML language and a character set are processing instructions. These import<br />

the <strong>Java</strong> language, utilities, and javafx.scene package as well as the javafx.scene.layout and javafx.scene.control<br />

packages, which are used to design the UI layout and the UI controls that the layout contains.<br />

For example, the StackPane UI layout container that you are using in the current application is in the javafx.<br />

scene.layout package, and the button UI control element is in the javafx.scene.control package. Because the<br />

FXML UI layout container is the parent element in this structure, it goes first, or outside the nested<br />

FXML UI definition structure that you are about to create.<br />

Inside the , you will nest children of the StackPane class (object), using the tags<br />

( XML tags are coded using ). Nested inside these tags are the UI control elements<br />

(in this case, a button control, so you would use the tag). Note that the class (object) proper name is used<br />

inside the arrowhead brackets to create the FXML tag, so this is very logical and should be quite easy to learn and<br />

assimilate into your UI design work process:<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

www.it-ebooks.info<br />

121

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!