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 4 ■ An Introduction to <strong>Java</strong>FX 8: Exploring the Capabilities of the <strong>Java</strong> 8 Multimedia Engine<br />

Using a <strong>Java</strong>FX Primary Stage Object: Creating a Floating Windowless Application<br />

Let’s make the primary Stage for your InvinciBagel application transparent so that the Button UI control floats right<br />

on top of the OS desktop. This is something that <strong>Java</strong>FX can do that you do not see very often, and it allows you to<br />

create 3D applications that float on top of the OS desktop (for 3D virtual objects, this is called a windowless<br />

ActiveX control).<br />

This is accomplished by using the StageStyle.TRANSPARENT constant, in conjunction with the .initStyle()<br />

method, from the Stage class. As Figure 4-4 demonstrates, I also used the technique I told you about in Chapter 3<br />

(a technique that does not follow the proper <strong>Java</strong> coding convention regarding declaring an import statement for<br />

classes you are planning to use). In line 35 of the code, I reference the constant by using the fully qualified class<br />

name (package.subpackage.class.constant), javafx.stage.StageStyle.TRANSPARENT, inside the primaryStage.<br />

initStyle(StageStyle style) method call. This is done via the following line of <strong>Java</strong> code:<br />

primaryStage.initStyle(javafx.stage.StageStyle.TRANSPARENT);<br />

Figure 4-4. Call an .initStyle() method with the StageStyle.TRANSPARENT constant, off the primaryStage Stage object<br />

As you can, I clicked the primaryStage Stage object in NetBeans IDE 8.0, in the code editing area, and it shows<br />

(tracks) the usage of that object in the code. The Stage object is set up (displaying title, style, and scene), using the<br />

.setTitle(), .initStyle(), .setScene(), and .show() method calls.<br />

I am going to leave the .setTitle() method call in the code, but make a mental note that once you get this<br />

windowless application treatment working, the title bar is part of the window’s “chrome,” or UI elements, and when<br />

these are gone (including the title bar), this setting of the title will amount to a moot point.<br />

If you have been worrying about memory optimization, at this point in the application development work<br />

process, you would remove the .setTitle() method call, because the title would not be shown using a StageStyle.<br />

TRANSPARENT constant for the StageStyle attribute.<br />

90<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!