![]() | Session 7 | ![]() |
Introduction
JavaFX is a framework for developing Java GUI (graphical user interface) programs. This session material serves two purposes. First, it presents the basics of JavaFX programming. Second, it uses JavaFX to demonstrate object-oriented programming and design.
Historically, there have been many possibilities for creating graphical user interfaces in Java. When Java was introduced, the GUI classes were bundled into a library known as the Abstract Windows Toolkit (
AWT
). AWT can be used for developing simple GUIs, but not for developing comprehensive GUI projects. The AWT user-interface components have been replaced with a more robust, versatile, and flexible library known as Swing components. Swing
is now replaced by a completely new GUI platform known as JavaFX
. It has a large functionality which cannot be covered within one practice session. In this session, we will study a few examples in order to get a taste of JavaFX and guidelines how to use this library on your own.
Before we will proceed with the first JavaFX program, make a few preliminary steps:
- save and unzip the initial project: project.zip
- check IntelliJ updates (Help->Check for updates) and plug in Gradle (File->Settings->Plugins)
- open a new project (File->Open) and browse for the folder which contains build.gradle (not subfolder src)

- in the new window, choose the following options:

- once the installation is completed, open build.gradle and make sure that mainClassName = is assigned the name of the main class:

- next open gradle menu (View->Tool Windows->Gradle) and run the program (double click on run launches the main class set in build.gradle):

Check if the JavaFX plugin is enabled in IntelliJ (File -> Settings -> Plugins). Then create a project as usually (New -> Project), but on the first page of the wizard, in the left-hand pane, select JavaFX:

In the JavaFX project, there are some classes already (Main
and Controller
) in the package sample
. Try to run Main
program and we will get the first (empty) graphical window.
![]() | Session 7 | ![]() |