Skip to content

Commit

Permalink
javaFxPart1: Tweak intro to JavaFX GUI structure
Browse files Browse the repository at this point in the history
Adapated from #89 by @laney0808
  • Loading branch information
damithc committed Sep 29, 2024
1 parent a962486 commit c7a42cf
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions tutorials/javaFxPart1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@

# JavaFX tutorial part 1 – Getting started

## Lifecycle of a JavaFX application
## The structure of a JavaFX GUI

Imagine yourself as a director of a play. First you provision the props that you will feature in your play. These can be hand props for your actors to interact with or even set dressings just to liven up the background. You then decide where to place the props for every scene. With a proper script in hand, you can finally approach a theatre and request for a stage. Thereafter, it’s just a matter of pulling the curtains on your masterpiece.
A JavaFX application is like a play you are directing. Instead of creating props, you create `Node`s (`Node`s are the fundamental building blocks of a JavaFX application), and place them onto a `Scene` (a scene is a graph of `Node`s). Then, you set your `Scene` on a `Stage` provided by JavaFX. When you call `Stage#show()` method, JavaFX renders a window with your `Stage` on it.

<puml src="images/javafx/JavaFxHierarchy.puml" />

A JavaFX application is like a play you are directing. Instead of creating props, you create `Node`s (`Node`s are the fundamental building blocks of a JavaFX application), and place them onto a `Scene` (a scene is a graph of `Node`s). Then, you set your `Scene` on a `Stage` provided by JavaFX. When you call `Stage#show()` method, JavaFX renders a window with your `Stage` on it.
More specifically,

* the `Stage` is like a window in a desktop application. It is the top-level container for a JavaFX application.
* a `Scene` is a container for `Node`s. A stage contains multiple scenes, and shows different scenes at different times based on programme state, user actions, etc.
* a `Node` is a component that can be added to a `Scene`. `Node`s can be simple controls like `Label`, `Button`, etc., or complex controls like `TableView`, `TreeView`, etc. A `Node` can contain other `Node`s too.
* a `Root Node` is the topmost `Node` in a `Scene`, the parent of all other `Node`s. It is usually a pane like `StackPane`, `BorderPane`, etc.

Well, that's a very high-level view of how JavaFX works. The actual implementation of a Java FX is a bit more (ahem...) "involved". This tutorial takes you through the steps of building a typical Java FX application, using a chatbot application called Duke as a running example. Given below is what the end result can look like if you follow this tutorial until the end:

Expand Down

0 comments on commit c7a42cf

Please sign in to comment.