Lesson 76Elective: Desktop apps with JavaFX
JavaFX overview, features, and architecture
Why Java needed a new GUI toolkit, what JavaFX offers, the layers between your code and the screen, and the Stage, Scene, and node structure every application shares.
By BasithUpdated 65 min
- GUI
- event-driven
- AWT
- Swing
- JavaFX
- key features
Most programs in this course talk to their user through a terminal: print a line, read a line. A JavaFX program opens a window instead, fills it with text, buttons and fields, and then waits for the user to do something. Before any code, this lesson builds the picture you need to read JavaFX code: how a window program runs, where JavaFX came from, what each of its layers does, and the three objects every JavaFX application is made of.
- Explain how a window program differs from a console program, and what the event loop does with every click.
- Compare AWT, Swing and JavaFX, and say what really happened to Swing.
- Say what JavaFX is, and explain each of its main features in a sentence or two.
- Draw the JavaFX architecture and say what every box does, from the JavaFX API down to the JVM.
- Describe an application as a Stage, a Scene and a scene graph of nodes, including the five stage styles and the three types of node.
start method. Clicks are answered by lambdas, and window styles come from an enum. All of it runs on one dedicated thread, which is why one slow method can freeze a whole window.What changes when a program has a window#
Think back to the console programs you wrote with Scanner. Your code was in charge. It printed a prompt, called nextLine(), and stopped dead until the user pressed Enter. Then it decided what to do next. The program asked the questions, in the order it chose.
A window turns this around. Once the window is on screen, the user can click any of ten buttons, type in any field, drag the window, resize it or close it, in any order. A program that stopped to wait for one particular answer would stop everything else too, including redrawing its own window. So a window program never waits for one answer. It leaves instructions in advance, such as “when the Save button is clicked, run this method”, and lets the user act. Each thing the user does is an event (a click, a key press, a resize), and the method you attach to it is an event handler. Programs built this way are called event-driven.
scanner.nextLine() and wait for the answer.main reaches its last line.Key ideaIn a window program the user acts first and the toolkit calls your code. Your job is to leave handlers in place and let each one finish quickly.
The event loop#
Something has to do the waiting. Inside JavaFX is a loop you never write, the event loop, running on a single thread called the JavaFX Application Thread for as long as the program runs. Each time round, it does this:
- 1The operating system notices something physical: the left mouse button went down at a point inside your window.
- 2It delivers that to your window as an event, which joins a queue of events waiting to be handled.
- 3The loop takes the next event off the queue.
- 4It works out which part of the window is under that point, say the Save button.
- 5It calls the handler you attached to the Save button, and waits for that handler to return.
- 6It redraws whatever the handler changed, then goes back to step 3.
This shape has a name, inversion of control. In a console program your code calls the library when it wants input. In a window program the library calls your code when input arrives.
AWT, Swing and JavaFX#
Java has had three toolkits for building windows. Each one answers a weakness of the one before.
AWT, the Abstract Window Toolkit (package java.awt), came with Java 1.0 in 1996. When you create an AWT button, AWT asks the operating system to create a real native button and keeps a hidden peerobject connected to it. The button looks like every other button on that system, but AWT can only offer widgets that every operating system has, and each system's widgets behave a little differently, so the same program could misbehave on one system and work on another. AWT is fine for a simple interface and weak for a large one.
Swing (package javax.swing, part of Java 1.2 in 1998) took the opposite route. It asks the operating system only for a plain top-level window, then paints every button, list and table itself with Java code. Components drawn this way are called lightweight. Because the drawing is Java's own, they behave the same on every platform and lean far less on native resources. Swing also added the components AWT lacked, such as tables, trees, tabbed panes and sliders.
JavaFXfirst appeared in December 2008, programmed through a separate scripting language called JavaFX Script. In 2011, JavaFX 2.0 rebuilt it as an ordinary Java library, the one you will use. It draws a scene graph through the graphics card and adds CSS styling, FXML, animation, media playback and an embedded web browser. JavaFX 8 shipped inside Oracle's JDK 8 in 2014. From Java 11 it is no longer bundled with the JDK: it is developed as a separate project, OpenJFX, and downloaded from openjfx.io, which is why the next lesson needs a section on compiling.
| AWT | Swing | JavaFX | |
|---|---|---|---|
| Arrived | 1996, in Java 1.0 | 1998, in Java 1.2 | 2008; a plain Java library since 2011 |
| Package | java.awt | javax.swing | javafx.* (javafx.scene, javafx.stage and more) |
| Who draws a button | The operating system, through a native peer | Swing itself, painted in Java (lightweight) | Prism, JavaFX's renderer, using the graphics card |
| Good at | Simple interfaces with a native look | Large interfaces that look the same everywhere | Modern interfaces: CSS, FXML, animation, media, web pages, 2D and 3D |
| Weak at | Few components; platform-specific bugs | Styling means Java painting code; no media or web view | Needs a separate download since Java 11 |
| Today | Still in every JDK (module java.desktop) | Still in every JDK (module java.desktop) | Outside the JDK as OpenJFX, with a new release every six months |
java.desktop), and large programs still run on it, IntelliJ IDEA's own interface among them. It was JavaFX that left the JDK, in Java 11.What JavaFX is#
JavaFX started out as a Java library for building rich internet applications, the 2008 term for programs delivered through the web that felt like desktop software, the territory of Adobe Flash and Microsoft Silverlight. A JavaFX program could run inside a web page through Java's browser plug-in, and JavaFX was promoted for desktops, phones and TVs. Browser plug-ins have since disappeared. Today JavaFX is a library for desktop applications on Windows, macOS and Linux; phones and tablets are reachable only through third-party ports such as Gluon's.
Two of its early promises still hold. First, JavaFX is one library for things that used to need several: media, UI controls, web content, 2D and 3D graphics. Before it, a Java program that wanted a video, a web page and modern controls had to stitch separate libraries together. JavaFX can also use the existing Java libraries, Swing included. Second, JavaFX draws through the GPU (graphics processing unit), the chip in your computer built for drawing. These hardware-accelerated graphics keep animation smooth, and because animation and controls share one system, a button can fade in or slide across the window like any other shape.
What JavaFX offers#
Here is what JavaFX gives you, each with what it means when you sit down to write a program.
- It is written in Java and runs on the JVM, so the same program runs on Windows, macOS and Linux: it is platform independent. One footnote: the lowest layers, the ones that talk to the operating system and the graphics card, are native code built separately for each system, which is why you download JavaFX for your own operating system. Your Java code stays the same.
- FXML is a markup language for describing an interface instead of building it in Java. It is XML, with tags and attributes that look like HTML. A line such as
<Button text="Save" onAction="#save"/>declares a button whose click runs a method calledsavein a Java controller class. The layout lives in the.fxmlfile and the logic in Java, so each can change without touching the other. - Scene Builder is a free drag-and-drop designer, now maintained by Gluon: you place controls on a canvas and it writes the FXML for you. It works alongside IntelliJ IDEA, Eclipse, NetBeans and VS Code.
- It works with Swing.
SwingNodeputs Swing components inside a JavaFX window, andJFXPanelputs JavaFX content inside a Swing window, so an old Swing application can move to JavaFX one screen at a time. - It has ready-made controls, the parts of a window a user clicks or types into, in
javafx.scene.control:Button,Label,TextField,CheckBox,RadioButton,TableView,ComboBoxand many more. The controls and layouts lesson covers the ones this track uses. - You style it with CSS, the same idea as on the web: colours, fonts, borders and backgrounds are set with CSS rules, using JavaFX property names that start with
-fx-. The rule.button { -fx-background-color: steelblue; -fx-text-fill: white; }in a stylesheet restyles every button in the program without touching the Java. - A Canvas is a blank surface you paint on yourself, with calls such as
fillRectandstrokeLine, for drawings no ready-made node expresses. The printing API (javafx.print) opens the print dialog and sends any node to a printer. - Its API goes beyond windows and controls, to 2D and 3D graphics, multimedia and web content. It is written in modern Java, so you meet generics (
ObservableList<Node>), annotations (@Override), background threads and lambda expressions (button.setOnAction(e -> save())) throughout. - Shapes are built in: 2D shapes such as
Rectangle,CircleandPolygon, and 3D shapes such asBoxandSpherewith cameras and lights, all ordinary nodes that sit in a window beside buttons. - Everything is drawn by Prism, a hardware-accelerated rendering pipeline. It has its own section in the architecture below.
The JavaFX architecture#
JavaFX is built as a stack of layers. Read the diagram from the top, the side your code touches, down to the JVM at the bottom. Each layer uses the one beneath it and hides it from the ones above, so your program only ever talks to the top row.
From the top: the JavaFX API and the scene graph you build with it; the Quantum Toolkit, which connects them to the engine below; the JavaFX graphics engine, with Prism for drawing, Glass for windows and input, WebView for web pages and Media for sound and video, each standing on a native technology; then the JDK API and tools, and the Java Virtual Machine. The sections below take the boxes from the top down.
JavaFX API#
The JavaFX API is the set of classes and methods you write your program with: Stage, Scene, Button, Label, TextField and the rest. Like the Java library you already know, it is organised into packages. These seven are the ones you meet first.
| Package | What it holds | Classes you will meet |
|---|---|---|
javafx.animation | Transition-based animations applied to nodes: fill, fade, rotate, scale and translate | FadeTransition, RotateTransition, Timeline |
javafx.application | The application life cycle | Application, Platform |
javafx.css | The machinery behind CSS-like styling | Mostly used indirectly, through setStyle(...) and .css files |
javafx.event | Delivering and handling events | Event, ActionEvent, EventHandler |
javafx.geometry | 2D geometry (points, rectangles, bounds) and the spacing and alignment values layouts use | Point2D, Insets, Pos, HPos |
javafx.stage | The top-level containers, that is, windows | Stage, StageStyle, FileChooser |
javafx.scene | The scene graph itself, plus the sub-packages canvas, chart, control, effect, image, input, layout, media, paint, shape, text, transform and web | Scene, Node, Group; then Button (control), VBox (layout), Text (text), Color (paint), Rectangle (shape) |
The packages ship in a handful of modules: javafx.base, javafx.graphics, javafx.controls, javafx.fxml, javafx.media, javafx.web and javafx.swing. You will name modules when you compile in the next lesson. For now, it is enough to know that javafx.controls brings in the two modules it is built on, javafx.graphics and javafx.base.
Scene graph#
The scene graph is where every JavaFX interface starts. It is a tree of objects called nodesthat describes everything in the window: what is there, where it sits and what it looks like. You build the tree; JavaFX keeps it in memory and redraws the window from it whenever something in it changes. Change a label's text with setText and the window updates on its own, with no painting code from you.
Key ideaYou never paint a JavaFX window. You build a tree of nodes that describes it, and JavaFX turns that tree into pixels every time it changes.
A node is any visual object. Nodes come in four broad kinds:
- shapes, 2D and 3D, such as
Circle,Rectangle,Polygon,BoxandSphere; - controls, such as
Button,CheckBox,ChoiceBoxandTextArea; - containers, also called layout panes, which hold other nodes and arrange them, such as
BorderPane,GridPaneandFlowPane; - media elements:
ImageViewshows an image andMediaViewshows a video.
The tree follows a few rules:
- Every node has exactly one parent, except one: the root node, which has none.
- A node with children is a branch node; a node with no children is a leaf node. So a node can have any number of children, including none.
- A node instance can be added to a scene graph only once. Add a button that already sits in one container to a second container and JavaFX quietly takes it out of the first: the node moves, it is not copied. Two buttons on screen need two
Buttonobjects, and adding the same node twice to one container's children throws anIllegalArgumentExceptionabout duplicate children. - Every node can carry effects (a drop shadow, a blur), an opacity from 0 (invisible) to 1 (solid), transforms (rotate, scale, move), event handlers, and application-specific state: your own data attached to the node, such as an id string or an object stored with
setUserData. Effects, opacity and transforms set on a branch apply to its whole subtree: fade a container to half opacity and everything inside it fades with it.
VBox columns. The code adds one Button object, save, to the left column's children and then to the right column's children. What does the user see?Quantum Toolkit#
Quantum is the middle layer. It connects the higher-level parts of JavaFX, the API and the scene graph, with the graphics and windowing systems underneath, and it is the reason your code never talks to Prism or Glass directly. It coordinates four kinds of work:
- Rendering: getting buttons, labels and shapes drawn on screen, by handing the scene graph's changes to Prism.
- Input events: mouse clicks, key presses and touches arriving from Glass, delivered to the right scene.
- Windowing: opening, closing, sizing and positioning windows, through Glass.
- JavaFX application operations: the rest of the traffic between JavaFX and the system underneath, such as starting the toolkit and shutting it down.
Oracle's own description of the architecture adds one more job: Quantum manages the threading rules that keep rendering and event handling apart.
The JavaFX graphics engine#
The large box in the middle of the diagram holds eight names. Four are parts of JavaFX; the other four are the native technologies those parts stand on.
| JavaFX part | What it does | Native technology underneath |
|---|---|---|
| Prism | Renders 2D and 3D graphics, using the GPU for hardware acceleration | OpenGL or Direct3D (D3D), the graphics APIs; Apple's Metal on macOS since JavaFX 27 |
| Glass | Connects JavaFX to the operating system: windows, events, keyboard, mouse | Win32 on Windows or GTK on Linux (Cocoa on macOS), the windowing systems |
| WebView | Displays web content inside a JavaFX application | WebKit, the web engine |
| Media | Plays audio and video | GStreamer, the media framework |
Prism#
Prism is JavaFX's rendering engine, the part that actually draws. Everything visible goes through it: buttons, text, shapes, images, animations, 2D and 3D graphics. Prism uses the GPU when one is available, which is what keeps graphics and animation smooth. To reach the GPU it uses whichever graphics API the system offers: Direct3D on Windows, OpenGL on Linux, and Apple's Metal on macOS, the default there since JavaFX 27 (earlier releases used OpenGL on macOS too). Where no usable GPU exists, in some virtual machines for instance, Prism falls back to a slower software renderer and the program still runs. It draws on a thread of its own, so one frame can be drawn while the next is being prepared.
Glass#
Glass is JavaFX's low-level windowing toolkit, the bridge between your JavaFX application and the operating system. Its jobs:
- Creates and manages windows.
- Handles keyboard and mouse input.
- Manages screen and display information: how many screens there are, their sizes and resolutions (the class
javafx.stage.Screenreports what Glass found). - Handles window events such as opening, closing, resizing and moving.
- Communicates with the operating system on JavaFX's behalf for all of the above.
A detail from Oracle's architecture notes connects Glass to the event loop. Glass uses the operating system's own event queue and runs on the same thread as your JavaFX code. AWT kept separate native and Java threads; JavaFX does not, which is why every event handler you write runs on the one JavaFX Application Thread.
WebView#
WebView is a JavaFX component that displays web pages and web content inside your application. It is based on the WebKit browser engine, the engine behind Safari. With it you can:
- display HTML web pages;
- load a website from its URL;
- display content written in HTML, CSS and JavaScript;
- let the user interact with the page: follow its links, fill in its forms;
- combine web content with ordinary JavaFX controls in the same window.
The work is split between two classes. WebView is the node that displays the page. WebEngine, which every WebView owns, loads the page and controls it: load takes a URL, and loadContent("<h1>Hello</h1>") shows a string of HTML. Together they make your application a small web browser. Both live in the module javafx.web, which you must name when you compile and run.
import javafx.application.Application;import javafx.scene.Scene;import javafx.scene.web.WebEngine;import javafx.scene.web.WebView;import javafx.stage.Stage; public class MiniBrowser extends Application { @Override public void start(Stage stage) { WebView webView = new WebView(); // the node that displays the page WebEngine engine = webView.getEngine(); // loads and controls the page engine.load("https://openjfx.io"); stage.setTitle("Mini Browser"); stage.setScene(new Scene(webView, 900, 600)); stage.show(); } public static void main(String[] args) { launch(args); }}A 900 by 600 window titled "Mini Browser" showing the openjfx.io home page (the computer must be online). Links work: clicking one loads the next page inside the same WebView. WebView is in the javafx.web module, so the module list grows to --add-modules javafx.controls,javafx.web
Media engine#
The media engine plays audio and video. It is built on GStreamer, an open-source multimedia framework. Older tutorials list formats such as FLV that current JavaFX no longer plays. This is what it supports today:
| What current JavaFX plays | |
|---|---|
| Audio | MP3; WAV and AIFF (uncompressed); AAC in an MP4 container (.m4a) |
| Video | MP4 with H.264 or H.265 (HEVC) video and AAC sound. FLV is no longer supported. |
| Streaming | HTTP Live Streaming (HLS) playlists (.m3u8) |
The media classes are in the package javafx.scene.media (module javafx.media), in three parts:
Mediarepresents one media file, created from its location as a URI string.MediaPlayerplays the media:play(),pause(),stop(), volume, position.MediaViewis a node that displays a player's video in the scene graph. Sound needs no view: aMediaPlayeron its own plays an MP3.
import java.io.File;import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.scene.media.Media;import javafx.scene.media.MediaPlayer;import javafx.scene.media.MediaView;import javafx.stage.Stage; public class VideoDemo extends Application { @Override public void start(Stage stage) { // Media: the file itself, given as a URI string (file:/...) Media media = new Media(new File("ooty.mp4").toURI().toString()); // MediaPlayer: plays, pauses and stops it MediaPlayer player = new MediaPlayer(media); // MediaView: the node that shows the video in the scene graph MediaView view = new MediaView(player); view.setFitWidth(640); stage.setTitle("Video Demo"); stage.setScene(new Scene(new Group(view), 640, 360)); stage.show(); player.play(); } public static void main(String[] args) { launch(args); }}A 640 by 360 window titled "Video Demo" playing ooty.mp4 from the folder the program was started in. Needs the javafx.media module: --add-modules javafx.controls,javafx.media Give it an .flv file instead and new Media(...) throws a MediaException, because the format is not supported.
JDK API and tools, and the JVM#
The bottom two boxes are the Java platform you already know. The JDK API and tools are the standard libraries (java.lang, java.util, threads, files) and the development tools: the compiler javac, the launcher java, the debugger. JavaFX is built on them like any other Java library. The JVM is the foundation: it executes the bytecode, and a JavaFX application runs on it exactly as a console program does. If the line between the JDK and the JVM is hazy, revisit setup and the JVM.
One click through the layers#
To see the layers work together, follow a single click on a Save button whose handler changes a label to “Saved”.
- 1Operating system. You press the mouse button. The operating system works out which window is under the pointer and sends that window a native message.
- 2Glass owns that window, so it receives the message, on the JavaFX Application Thread, and turns it into an event JavaFX understands.
- 3Quantum passes the event to the scene shown in that window, as a
MouseEventcarrying the click's coordinates. - 4Scene graph. JavaFX finds the topmost node under the point, the Save button, and routes the event down the tree to it and back up. The button recognises a press followed by a release as a click and fires an
ActionEvent. - 5Your handler, the lambda you gave
setOnAction, runs on the same thread and callslabel.setText("Saved"). - 6Back down. The label is marked as changed and a pulse is scheduled. On the pulse, JavaFX recomputes CSS and layout and hands the change to Prism.
- 7Prism draws the new frame with the GPU, through Direct3D on Windows, and the window shows “Saved”.
The structure of a JavaFX application#
Every JavaFX application is made of three parts: a Stage, a Scene and nodes. The names come from the theatre. The stage is where the play happens, the scene is what is set up on it at the moment, and the nodes are everything in that scene.
Key ideaA Stage shows one Scene at a time, the Scene holds one root node, and every other node hangs somewhere below that root.
Stage#
A stage is a window, and it contains all the objects of a JavaFX application. It is an object of the class Stage in the package javafx.stage. You do not create the first one yourself: the primary stage is created by the platform, the JavaFX runtime, and passed as the argument to the start() method of your Application class. Extra windows, such as a dialog, are further Stage objects you create with new Stage().
x and y, the distances from the left and top edges of the screen. All four have setters: stage.setX(100) and stage.setY(50) move the window, while stage.setWidth(600) and stage.setHeight(400) resize it.A stage is divided into the content area, where your scene is drawn, and the decorations: the title bar and borders, drawn by the operating system. When you give a scene a size, say 600 by 300, that is the content area. The decorations go around it, so the window on screen is a little larger.
A stage has a style that decides its decorations. The styles are the values of the enum StageStyle (package javafx.stage), chosen with the stage's initStyle method. An enum is the natural type here: a fixed set of named choices. These five have been there from the start:
DECORATED: the default. A white background with the normal title bar and borders, including the minimise, maximise and close buttons.UNDECORATED: a white background with no title bar or border at all, as on a splash screen. With no title bar to drag or close it by, your program has to provide a way out.TRANSPARENT: no decorations and a transparent background, so only what your nodes draw is visible. Set the scene's fill toColor.TRANSPARENTas well, and a round clock can float on the desktop with no rectangle around it.UNIFIED: normal decorations, but no border between the title bar and the content, so the content's background runs up into the title bar. Only some platforms support it; elsewhere it falls back toDECORATED.UTILITY: a white background with minimal decorations, typically a slimmer title bar with only a close button, for small tool windows.
import javafx.application.Application;import javafx.scene.Group;import javafx.scene.Scene;import javafx.stage.Stage;import javafx.stage.StageStyle; public class UtilityWindow extends Application { @Override public void start(Stage primaryStage) { primaryStage.initStyle(StageStyle.UTILITY); // must come before show() primaryStage.setTitle("Tools"); primaryStage.setScene(new Scene(new Group(), 250, 150)); primaryStage.show(); } public static void main(String[] args) { launch(args); }}A small window, 250 by 150, titled "Tools", with a slim title bar and, on most systems, only a close button. Moving the initStyle line below show() makes it throw IllegalStateException: the style can only be chosen before the stage is first shown.
JavaFX 27 added a sixth value for good, EXTENDED, after trying it out as a preview in JavaFX 25 and 26. It stretches your content up into the title bar area, so your own nodes can sit there, together with a new HeaderBar control. This track sticks to the classic five.
One last point: nothing appears until you call the stage's show() method. Until then the stage is an object in memory and nothing more.
Scene#
A scene represents the physical contents of a JavaFX application: everything in the scene graph. It is an object of the class Scene in the package javafx.scene. At any instant a scene is added to only one stage, though a stage can swap in a different scene at any time with setScene, which is how a login screen gives way to a main screen in the same window.
You create a scene by instantiating Scene, passing it the root node and, if you like, its size: new Scene(root, 600, 300). The constructor takes the width first, so that scene is 600 pixels wide and 300 tall. A scene also has a fill, its background colour, white unless you change it. The next lesson builds scenes line by line.
Scene graph and nodes#
Two words to keep apart: the scene graph is a tree-like, hierarchical data structure representing the contents of a scene. A node is one visual object in it, of the four kinds you met above: geometrical objects, UI controls, containers and media elements. Each of them is a subclass of Node in javafx.scene, the superclass of all nodes. That shared superclass is what lets one container hold a Button, a Rectangle and an ImageView in a single list, the same polymorphism you used with your own class hierarchies.
By their place in the tree, nodes are of three types:
- A root node is the first node of the scene graph, the one at the top with no parent. It is the node you pass to the
Sceneconstructor. - A branch node, also called a parent node, is a node with child nodes. Their base class is
Parentinjavafx.scene, an abstract class, so you never writenew Parent(); you use one of its kinds, described below. - A leaf node is a node without child nodes, such as a
Rectangleor anEllipse(2D shapes), aBox(a 3D shape), anImageView(shows an image) or aMediaView(shows a video).
The parent nodes come in three kinds:
Group: a collective node that holds a list of children. When the group is rendered, its children are rendered in order, each drawn over the ones before it, and any transform or effect applied to the group applies to all of them. A group does not arrange its children: each one stays at the coordinates you gave it.Region: the base class of all the node-based UI controls and layout containers:Chart,Pane(and through itVBox,GridPaneand the other panes) andControl(and through itButton,TextFieldand the other controls). A region has a size of its own, can be resized, and can be styled with CSS.WebView: manages a web engine and displays its contents. It extendsParent, but you never add children to it yourself; what it shows comes from the web page.
Notice where the controls sit. Button descends from Region, and so from Parent, because a control draws itself with a few internal nodes. In the tree you build, though, a button has no children you add, so you treat it as a leaf. The controls and layouts lesson draws the whole class hierarchy.
Two more points about the root. First, it is mandatory. The Scene constructor will not work without one, and its parameter type is Parent, so a leaf such as a Rectangle cannot be a root: that call does not compile. Second, the kind of root changes what happens when the window is resized:
Here is the scene graph of a small but real window, with each node's type marked.
- Creating a JavaFX application: the Application class, launch and the lifecycle, then a brown empty window and a window of text, compiled and run on your own machine.
- Nodes, controls and layout panes: Group, Region and WebView as roots, the panes and controls, and the Node class hierarchy.
- Form creation: a registration form, built in five steps.
- Event handling: handlers, then the area calculator, perfect number, interest and Armstrong programs.
- A JavaFX application with a database: a student program and an employee program that keep their data in MySQL, using what you learned in JDBC basics and creating and executing queries.
Try it
Answer each one in your head or on paper first, then open the answer.
StageStyle fits each window: (a) an ordinary main window; (b) a splash screen with no title bar, shown while the program loads; (c) a small floating palette of drawing tools; (d) a round clock with no rectangle around it? When must initStyle be called? Finally, what do a stage's width and height set, and what sets its position?Practice
Work through these on your own. Each one builds on this page.
TextField display at the top and a 4 by 4 grid of buttons below it, inside a VBox root, with a GridPane holding the buttons. Mark each node as root, branch or leaf. How many nodes does the tree have? Why can one Button object not serve as all sixteen keys?openjfx.io and write one line on what it is for. Then find which module each package belongs to. Use what you find to explain why a program that plays a video needs javafx.media in its module list, while a program that only shows a Rectangle does not.song.mp3 but fails on clip.flv and holiday.mkv. Using the media formats table, explain both failures, and say what the friend could do to play the two videos.Short guides on this topic
Quick answers to what people search for about it, with code to run.
Spotted a mistake, or a part that did not make sense? Report it by email