Java Reference
In-Depth Information
JavaFX benefited from years of experience that engineers at Sun Microsystems (now Oracle)
gained creating desktop platforms such as Swing. Therefore, the JavaFX framework comes
loaded with features and functionalities that make it ready for production-grade deployment.
In this chapter, we are going to explore how to use fundamental building blocks to create
functional JavaFX applications. This chapter covers the following topics:
F Shapes—the most basic representation of a visual element is the geometric shape.
You will learn how to create simple and complex shapes using Shape classes.
F Text—besides geometric shapes, JavaFX facilitates the rendition of text as graphical
nodes as well. You will learn how to render text on the stage using the Text class.
F User-input-events—all visual components can receive user input through the mouse
and keyboard. You will see how to handle input events using event handler functions.
F Application-organization—as your application grows in complexity, it is
imperative that you modularize your code into logical components. We will
look at code organization using packages, member access modifiers, and
other modularization techniques.
Building a JavaFX application
The irst chapter of the topic introduced you to the fundamentals of the JavaFX language. Now,
you are ready to start building your own JavaFX desktop application. In this recipe, we will look
at the minimal requirements to build a runnable / JavaFX application.
Getting ready
In order to write your application, you will need to use an IDE or your favorite text editor. Refer
to Chapter 1 , Getting Started with JavaFX , to find out how to download and get started with
JavaFX with the NetBeans or Eclipse IDE.
How to do it...
The listing below shows how to create a simple, yet functional JavaFX application that uses
several components of the JavaFX application framework. The full listing of the code is
available at ch02/source-code/src/application/SimpleApplication.fx .
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
Search WWH ::

Custom Search