SlideShare a Scribd company logo
1 of 45
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
C HA PT E R 14
Creating GUI
Applications
with JavaFX
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Topics
Introduction
Scene Graphs
Using Scene Builder to Create JavaFX
Applications
Writing the Application Code
RadioButtons and CheckBoxes
Displaying Images
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Introduction
JavaFX is a Java library for developing
rich applications that employ graphics.
You can use it to create:
GUI applications, as well as applications that
display 2D and 3D graphics
standalone graphics applications that run on
your local computer
applications that run from a remote server
applications that are embedded in a Web
page
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Introduction
• A GUI (pronounced “gooey”) is a
graphical window or a system of
graphical windows presented by an
application for interaction with the
user.
• In addition to accepting input from the
keyboard, GUIs typically accept input
from a mouse, or a touch screen.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Introduction
A window in a GUI commonly consists
of several components that present
data to the user and/or allow
interaction with the application.
Some of the common GUI components
are buttons, labels, text fields, check
boxes, and radio buttons.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Various GUI Components
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Event-Driven Programming
Programs that operate in a GUI environment
must be event-driven.
An event is an action that takes place within
a program, such as the clicking of a button.
Part of writing a GUI application is creating
event listeners.
An event listener is a method that
automatically executes when a specific event
occurs.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Scene Graphs
In JavaFX, the components that are in a GUI are
organized as a scene graph.
A scene graph is a tree-like, hierarchical data
structure that contains nodes.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Scene Graphs
A scene graph can have three types of nodes:
Root Node:
The scene graph can have only one root node.
It is the parent of all the other nodes in the scene graph.
It is the first node in the structure.
Branch Node:
A branch node can have other nodes as children.
Leaf Node:
A leaf node cannot have children.
In a nutshell, the root node and branch nodes can have children,
but leaf nodes cannot.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Scene Graphs
In JavaFX, a node that can have
children is a container.
A container is a component that can
hold other components inside of it.
The JavaFX library provides several
different types of containers.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Scene Graphs
The AnchorPane container is commonly used as a
GUI’s root node.
A branch node is a container that is placed inside
the root node or inside another branch node.
For example, you might have a Pane (one of the
simplest JavaFX containers) inside of an
AnchorPane.
A leaf node is a component that is not a container.
For example, Button components and Label
components are leaf nodes.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Anchor
Pane is the
root node
The Pane is a
branch node
The Button, Label,
and Radio button
components are
leaf nodes
Root Node
Branch Node
Leaf Nodes
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The AnchorPane is the root node
The TitledPane is a child of the AnchorPane
it is contained inside the AnchorPane
Another AnchorPane is a child of the TitledPane
it is contained inside the TitledPane
The Three RadioButtons are children of the innermost
AnchorPane
The Button is a child of the root node AnchorPane.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Using Scene Builder to Create
JavaFX Applications
Scene Builder is a free design tool from Oracle for visually
creating GUIs.
It works like this:
Use Scene Builder to construct a GUI by dragging and dropping
the components that you need onto a blank window.
Visually arrange the components on the window and set various
component properties to create the appearance that you want
for the GUI.
Save the GUI to an FXML file.
FXML is a markup language that describes the components in a
JavaFX scene graph.
FXML uses tags to organize data, in a manner similar to the
way that HTML uses tags to format text in a Web browser.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Using Scene Builder to Create
JavaFX Applications
Visually creating a GUI with Scene Builder is
only part of the process.
Once you save a GUI’s scene graph to an
FXML file, the next step is to write Java code
that reads the FXML file and displays the GUI
on the screen and handles any events that
occur while the application is running.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Starting Scene Builder
You can download Scene Builder from the following location:
www.oracle.com/technetwork/java/javafx/downloads/
When you install Scene Builder in Windows, a shortcut is
automatically created on the desktop.
You can launch Scene Builder either by double-clicking the shortcut,
or by going to All Programs > JavaFX Scene Builder and clicking
JavaFX Scene Builder x.x
where x.x will be a version number such as 1.1 or 2.0
If you installed Scene Builder on a Mac, go to the Applications folder
and double-click the shortcut for JavaFX Scene Builder x.x
where x.x will be a version number such as 1.1 or 2.0
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Here is a brief summary of each part of
the main window:
Menu Bar
Scene Builder’s commands are located on the
menus that access the menu bar at the top of
the main window.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Library Panel
The Library Panel provides a list of JavaFX
components that you can use in an
application.
To place a component in a GUI, you simply
drag it from the Library Panel, and drop it into
the Content Panel.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Content Panel
The Content Panel is where you visually
design an application’s GUI.
It initially shows an AnchorPane as the GUI’s
root node.
You create other components in the GUI by
dragging them from the Library Panel and
dropping them onto the root node
component..
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Hierarchy Panel
The Hierarchy Panel shows the GUI’s scene
graph.
As you add components to the Content Panel,
nodes appear in the Hierarchy Panel.
You can use the Hierarchy Panel to select
nodes that you want to edit.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Selection Bar
This area of the screen shows the hierarchical
path of the currently selected node in the
scene graph.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
Inspector Panel
The Inspector Panel is divided into three
sections:
Properties
Layout
Code
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Scene Builder Main Window
The Properties section
allows you to view and edit the values of the selected
component’s properties, which are values that determine the
component’s appearance.
The Layout section
lets you specify values that control the way the component is
displayed when the GUI’s window is resized.
The Code section
allows you to assign an fx:id to a component, which is similar to
assigning a variable name to the component.
also allows you to designate event handlers to execute when
specific events happen to the selected component.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Using Scene Builder to Create
the Kilometer Converter GUI
An AnchorPane, as the root node
A Label to display the prompt Enter a distance in kilometers:
A TextField in which the user will enter a distance
A Label to display a message showing the distance converted to
miles
A Button that performs the conversion
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Writing the Application Code
Once you have saved an application’s
GUI to an FXML file, you can write the
Java code that runs the application.
A simple JavaFX application uses:
a main application class
a controller class
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Main Application Class
Once you have created a GUI with Scene
Builder, and saved it to an FXML file, you
need to write a Java class that performs
the following:
Loads the FXML file
Builds the scene graph in memory
Displays the GUI
Example: KilometerCoverter.java
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
The Controller Class
The controller class is responsible for handling
events that occur while the application is running.
The controller class contains the following items:
The necessary import statements
Private variables to reference the components that
have a fx:id in the scene graph
An initialize method that is automatically called after
the FXML file is loaded
Event listener methods
Example: KilometerCoverterController.java
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Using the Sample Controller
Skeleton
An alternative for manually typing the code for the controller
class, Scene Builder can provide a sample "skeleton" for the
controller class.
To see the sample controller skeleton, click the View menu,
then click Show Sample Controller Skeleton
You can click the Copy button to copy the sample code to the
clipboard, and then paste it into an editing window in your IDE.
The obvious benefit of using the sample skeleton controller is
that a lot of the code is written for you.
The skeleton has all of the necessary import statements, and
the class already has private field declarations for all of the
components that have an fx:id.
You just need to change the name of the class, and write the
code for the event listener methods.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Summary of Creating a JavaFX
Application
Use Scene Builder to design the GUI. Be sure to give an fx:id to
all of the components that you plan to access in your Java
code. Save the GUI as an FXML file.
Write the code for the main application class, which loads the
FXML file and launches the application. Save and compile the
code in the same location as the FXML file.
Write the code for the controller class, which contains the
event handler methods for the GUI. Save and compile the code
in the same location as the FXML file.
In Scene Builder, register the controller class, then register an
event handler method for each component that needs to
respond to events. Save the FXML file again.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
RadioButtons and
CheckBoxes
RadioButtons normally appear in
groups of two or more and allow the
user to select one of several possible
options.
CheckBoxes, which may appear alone
or in groups, allow the user to make
yes/no or on/off selections.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
RadioButtons
RadioButtons are useful when you
want the user to select one choice from
several possible options.
A radio button may be selected or
deselected.
Each radio button has a small circle
that appears filled-in when the radio
button is selected and appears empty
when the radio button is deselected.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Creating a RadioButton
To create a RadioButton, you simply drag it
from the Library panel and drop it onto the
Content panel.
(The RadioButton component is found in the
Controls section of the Library panel.)
RadioButtons have a Text property that
determines the text they display.
RadioButtons normally are in a toggle group.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Adding RadioButtons to a
Toggle Group
Here are the steps for adding RadioButtons to a
toggle group:
Create the first RadioButton component in the Content panel.
Open the Properties section of the Inspector Panel, and find the
Toggle Group property.
Enter the name you wish to give the toggle group.
Create the next RadioButton.
For its Toggle Group property, you should be able to click the
down-arrow and select the toggle group that you created for the
first RadioButton.
Repeat this for each subsequent RadioButton that you want in
the same toggle group.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Determining in Code Whether
a RadioButton Is Selected
In the controller class, you can use the RadioButton's
isSelected method to determine whether the RadioButton is
selected or not.
The isSelected method returns a boolean value.
If the RadioButton is selected, the method returns true .
Otherwise, it returns false .
Example: RadioButtonDemo.java, RadioButtonDemoController.java
if (radio.isSelected())
{
// Code here executes if the
radio
// button is selected.
}
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Responding to RadioButton
Events
In many situations you want an action to take
place at the time the user clicks a
RadioButton.
you must write an event listener method in the
controller class for each RadioButton
and then select the appropriate method as the
event listener in Scene Builder.
Example: RadioButtonEvent.java, RadioButtonEventController.java
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
CheckBoxes
A CheckBox is a small box with text
appearing next to it.
Like RadioButtons, CheckBoxes may be
selected or deselected at run time.
When a CheckBox is selected, a small check
mark appears inside the box.
Although CheckBoxes are often displayed in
groups, they are not usually grouped in a
toggle group like RadioButtons are.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Creating a CheckBox
To create a CheckBox, you simply drag it
from the Library panel and drop it onto the
Content panel.
(The CheckBox component is found in the
Controls section of the Library panel.)
CheckBoxes have a Text property that
determines the text they display.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Determining in Code Whether
a CheckBox Is Selected
In the controller class, you can use the CheckBox’s
isSelected method to determine whether the CheckBox is
selected or not.
The isSelected method returns a boolean value.
If the CheckBox is selected, the method returns true .
Otherwise, it returns false .
Example: CheckBoxDemo.java, CheckBoxDemoController.java
if (checkbox.isSelected())
{
// Code here executes if the
// CheckBox is selected.
}
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Responding to CheckBox
Events
Sometimes you want an action to take place
at the time the user clicks a CheckBox.
you must write an event listener method in the
controller class for the CheckBox
and then select the method as the event
listener in Scene Builder.
Example: CheckBoxEvent.java, CheckBoxEventController.java
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Displaying Images
You can use the ImageView component to display
images in an application's GUI.
You simply drag the component from the Library
panel (you will find it in the Controls section) and
drop it onto the Content Panel
Once you have created a ImageView component, you
use its Image property to specify the image that it
will display.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Displaying an Image with
Code
Sometimes you might need to write
code that will change the image being
displayed in an ImageView component,
as the application is running.
In your controller class, you can call
the ImageView component's setImage
method to do this.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Displaying an Image with
Code
First, you must create an instance of the Image
class, which can read the contents of an image file.
The Image class is in the javafx.scene.image
package.
The Image class constructor accepts a String
argument that is the name of an image file.
Here is an example:
Image myImage = new Image("Dog.jpg");
Here is an example that uses a path.
Image myImage = new Image("C:Chapter14" +
"ImagesDog.jpg");
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
Displaying an Image with
Code
Once you have created an Image object, you pass a
reference to that object to the ImageView
component's setImage method.
The following is an example:
Assume that myImageView references an ImageView
component, and myImage references an Image object.
myImageView.setImage(myImage);
Example: ImageViewDemo.java, ImageViewDemoController.java

More Related Content

What's hot

OSCON Titanium Tutorial
OSCON Titanium TutorialOSCON Titanium Tutorial
OSCON Titanium TutorialKevin Whinnery
 
Develop Mobile App Using Android Lollipop
Develop Mobile App Using Android LollipopDevelop Mobile App Using Android Lollipop
Develop Mobile App Using Android LollipopEdureka!
 
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012itslearning Nederland
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryRuss Weakley
 
Learn How to Animate your Android App
Learn How to Animate your Android AppLearn How to Animate your Android App
Learn How to Animate your Android AppEdureka!
 
Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Manoj Ellappan
 
Java applets and working principles
Java applets and working principlesJava applets and working principles
Java applets and working principlesDAZZLING DAZZLING
 
Design Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsDesign Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsEdureka!
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?Russ Weakley
 
Java applet basics
Java applet basicsJava applet basics
Java applet basicsSunil Pandey
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labelsRuss Weakley
 
Android development 1july
Android development 1julyAndroid development 1july
Android development 1julyEdureka!
 
Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleSandeep Hijam
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and ErrorsRuss Weakley
 
Shibapratim Bagchi HTML tutorial
Shibapratim Bagchi HTML tutorialShibapratim Bagchi HTML tutorial
Shibapratim Bagchi HTML tutorialShibapratim Bagchi
 

What's hot (20)

OSCON Titanium Tutorial
OSCON Titanium TutorialOSCON Titanium Tutorial
OSCON Titanium Tutorial
 
Develop Mobile App Using Android Lollipop
Develop Mobile App Using Android LollipopDevelop Mobile App Using Android Lollipop
Develop Mobile App Using Android Lollipop
 
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012
itslearning App Library dag voor partners - Tim Remmers - 12 juni 2012
 
Accessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and gloryAccessibility in Design systems - the pain and glory
Accessibility in Design systems - the pain and glory
 
Part1
Part1Part1
Part1
 
Learn How to Animate your Android App
Learn How to Animate your Android AppLearn How to Animate your Android App
Learn How to Animate your Android App
 
Android app development guide for freshers by ace web academy
Android app development guide for freshers  by ace web academyAndroid app development guide for freshers  by ace web academy
Android app development guide for freshers by ace web academy
 
Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4Basic iOS Training with SWIFT - Part 4
Basic iOS Training with SWIFT - Part 4
 
Java applets and working principles
Java applets and working principlesJava applets and working principles
Java applets and working principles
 
Design Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design ProblemsDesign Patterns : Solution to Software Design Problems
Design Patterns : Solution to Software Design Problems
 
What are accessible names and why should you care?
What are accessible names and why should you care?What are accessible names and why should you care?
What are accessible names and why should you care?
 
Elixir tutorial
Elixir tutorialElixir tutorial
Elixir tutorial
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
Creating Acessible floating labels
Creating Acessible floating labelsCreating Acessible floating labels
Creating Acessible floating labels
 
Android development 1july
Android development 1julyAndroid development 1july
Android development 1july
 
New Introductionfor Flash Designers
New Introductionfor Flash DesignersNew Introductionfor Flash Designers
New Introductionfor Flash Designers
 
Introduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning SimpleIntroduction to Docker and Containers- Learning Simple
Introduction to Docker and Containers- Learning Simple
 
Accessible Form Hints and Errors
Accessible Form Hints and ErrorsAccessible Form Hints and Errors
Accessible Form Hints and Errors
 
Angular material
Angular materialAngular material
Angular material
 
Shibapratim Bagchi HTML tutorial
Shibapratim Bagchi HTML tutorialShibapratim Bagchi HTML tutorial
Shibapratim Bagchi HTML tutorial
 

Similar to Eo gaddis java_chapter_14_5e

Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxGevitaChinnaiah
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.pptTabassumMaktum
 
Programming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & ExtensionProgramming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & ExtensionMahmoud Samir Fayed
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Mikkel Flindt Heisterberg
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Mikkel Flindt Heisterberg
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Ryan Baxter
 
235042632 super-shop-ee
235042632 super-shop-ee235042632 super-shop-ee
235042632 super-shop-eehomeworkping3
 
GoogleDSC_ GHRCE_ flutter_firebase.pptx
GoogleDSC_ GHRCE_  flutter_firebase.pptxGoogleDSC_ GHRCE_  flutter_firebase.pptx
GoogleDSC_ GHRCE_ flutter_firebase.pptxGoogleDeveloperStude22
 
Slot04 creating gui
Slot04 creating guiSlot04 creating gui
Slot04 creating guiViên Mai
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayLiz Sims
 
Web application development process
Web application development processWeb application development process
Web application development processJohn Smith
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by CitytechRitwik Das
 
Lesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxLesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxEllenGracePorras
 
Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textToma Velev
 
Getting started with ibm worklight tips
Getting started with ibm worklight tipsGetting started with ibm worklight tips
Getting started with ibm worklight tipsbupbechanhgmail
 

Similar to Eo gaddis java_chapter_14_5e (20)

Lecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptxLecture 1 Introduction to React Native.pptx
Lecture 1 Introduction to React Native.pptx
 
GUI design using JAVAFX.ppt
GUI design using JAVAFX.pptGUI design using JAVAFX.ppt
GUI design using JAVAFX.ppt
 
Programming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & ExtensionProgramming Without Coding Technology (PWCT) Features - Framework & Extension
Programming Without Coding Technology (PWCT) Features - Framework & Extension
 
Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)Plug yourself in and your app will never be the same (2 hr editon)
Plug yourself in and your app will never be the same (2 hr editon)
 
Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)Plug yourself in and your app will never be the same (2 hour edition)
Plug yourself in and your app will never be the same (2 hour edition)
 
Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)Plug yourself in and your app will never be the same (1 hr edition)
Plug yourself in and your app will never be the same (1 hr edition)
 
dot net
dot netdot net
dot net
 
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...Lotusphere 2011  Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
Lotusphere 2011 Jmp103 - Jumpstart Your "Jedi Plug-in Development Skills" wi...
 
235042632 super-shop-ee
235042632 super-shop-ee235042632 super-shop-ee
235042632 super-shop-ee
 
Codename one
Codename oneCodename one
Codename one
 
GoogleDSC_ GHRCE_ flutter_firebase.pptx
GoogleDSC_ GHRCE_  flutter_firebase.pptxGoogleDSC_ GHRCE_  flutter_firebase.pptx
GoogleDSC_ GHRCE_ flutter_firebase.pptx
 
Slot04 creating gui
Slot04 creating guiSlot04 creating gui
Slot04 creating gui
 
Java Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage EssayJava Is A Programming Dialect And Registering Stage Essay
Java Is A Programming Dialect And Registering Stage Essay
 
Web application development process
Web application development processWeb application development process
Web application development process
 
Open sap ui5 - week_2 unit_1_syjewa_exercises
Open sap ui5  - week_2 unit_1_syjewa_exercisesOpen sap ui5  - week_2 unit_1_syjewa_exercises
Open sap ui5 - week_2 unit_1_syjewa_exercises
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Lesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptxLesson 4 Introduction to Human Computer Interaction.pptx
Lesson 4 Introduction to Human Computer Interaction.pptx
 
GUI_part_1.pptx
GUI_part_1.pptxGUI_part_1.pptx
GUI_part_1.pptx
 
Flutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - textFlutter vs Java Graphical User Interface Frameworks - text
Flutter vs Java Graphical User Interface Frameworks - text
 
Getting started with ibm worklight tips
Getting started with ibm worklight tipsGetting started with ibm worklight tips
Getting started with ibm worklight tips
 

More from Gina Bullock

Eo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eEo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eGina Bullock
 
Eo gaddis java_chapter_14_5e
Eo gaddis java_chapter_14_5eEo gaddis java_chapter_14_5e
Eo gaddis java_chapter_14_5eGina Bullock
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eGina Bullock
 
Eo gaddis java_chapter_11_5e
Eo gaddis java_chapter_11_5eEo gaddis java_chapter_11_5e
Eo gaddis java_chapter_11_5eGina Bullock
 
Eo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eEo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eGina Bullock
 
Eo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eEo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eGina Bullock
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eGina Bullock
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eGina Bullock
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eGina Bullock
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eGina Bullock
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eGina Bullock
 
Eo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eEo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eGina Bullock
 
Eo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5eEo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5eGina Bullock
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eGina Bullock
 
Eo gaddis java_chapter_16_5e
Eo gaddis java_chapter_16_5eEo gaddis java_chapter_16_5e
Eo gaddis java_chapter_16_5eGina Bullock
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eGina Bullock
 
Eo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eEo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eGina Bullock
 
Eo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eEo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eGina Bullock
 
Eo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5eEo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5eGina Bullock
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eGina Bullock
 

More from Gina Bullock (20)

Eo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eEo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5e
 
Eo gaddis java_chapter_14_5e
Eo gaddis java_chapter_14_5eEo gaddis java_chapter_14_5e
Eo gaddis java_chapter_14_5e
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
Eo gaddis java_chapter_11_5e
Eo gaddis java_chapter_11_5eEo gaddis java_chapter_11_5e
Eo gaddis java_chapter_11_5e
 
Eo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eEo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5e
 
Eo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eEo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5e
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5e
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5e
 
Eo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5eEo gaddis java_chapter_04_5e
Eo gaddis java_chapter_04_5e
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5e
 
Eo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5eEo gaddis java_chapter_06_5e
Eo gaddis java_chapter_06_5e
 
Eo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5eEo gaddis java_chapter_10_5e
Eo gaddis java_chapter_10_5e
 
Eo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5eEo gaddis java_chapter_07_5e
Eo gaddis java_chapter_07_5e
 
Eo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5eEo gaddis java_chapter_01_5e
Eo gaddis java_chapter_01_5e
 
Eo gaddis java_chapter_16_5e
Eo gaddis java_chapter_16_5eEo gaddis java_chapter_16_5e
Eo gaddis java_chapter_16_5e
 
Eo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5eEo gaddis java_chapter_12_5e
Eo gaddis java_chapter_12_5e
 
Eo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5eEo gaddis java_chapter_09_5e
Eo gaddis java_chapter_09_5e
 
Eo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5eEo gaddis java_chapter_08_5e
Eo gaddis java_chapter_08_5e
 
Eo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5eEo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5e
 
Eo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5eEo gaddis java_chapter_05_5e
Eo gaddis java_chapter_05_5e
 

Recently uploaded

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Recently uploaded (20)

Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

Eo gaddis java_chapter_14_5e

  • 1. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C HA PT E R 14 Creating GUI Applications with JavaFX
  • 2. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Topics Introduction Scene Graphs Using Scene Builder to Create JavaFX Applications Writing the Application Code RadioButtons and CheckBoxes Displaying Images
  • 3. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Introduction JavaFX is a Java library for developing rich applications that employ graphics. You can use it to create: GUI applications, as well as applications that display 2D and 3D graphics standalone graphics applications that run on your local computer applications that run from a remote server applications that are embedded in a Web page
  • 4. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Introduction • A GUI (pronounced “gooey”) is a graphical window or a system of graphical windows presented by an application for interaction with the user. • In addition to accepting input from the keyboard, GUIs typically accept input from a mouse, or a touch screen.
  • 5. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Introduction A window in a GUI commonly consists of several components that present data to the user and/or allow interaction with the application. Some of the common GUI components are buttons, labels, text fields, check boxes, and radio buttons.
  • 6. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Various GUI Components
  • 7. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley
  • 8. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Event-Driven Programming Programs that operate in a GUI environment must be event-driven. An event is an action that takes place within a program, such as the clicking of a button. Part of writing a GUI application is creating event listeners. An event listener is a method that automatically executes when a specific event occurs.
  • 9. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scene Graphs In JavaFX, the components that are in a GUI are organized as a scene graph. A scene graph is a tree-like, hierarchical data structure that contains nodes.
  • 10. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scene Graphs A scene graph can have three types of nodes: Root Node: The scene graph can have only one root node. It is the parent of all the other nodes in the scene graph. It is the first node in the structure. Branch Node: A branch node can have other nodes as children. Leaf Node: A leaf node cannot have children. In a nutshell, the root node and branch nodes can have children, but leaf nodes cannot.
  • 11. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scene Graphs In JavaFX, a node that can have children is a container. A container is a component that can hold other components inside of it. The JavaFX library provides several different types of containers.
  • 12. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Scene Graphs The AnchorPane container is commonly used as a GUI’s root node. A branch node is a container that is placed inside the root node or inside another branch node. For example, you might have a Pane (one of the simplest JavaFX containers) inside of an AnchorPane. A leaf node is a component that is not a container. For example, Button components and Label components are leaf nodes.
  • 13. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Anchor Pane is the root node The Pane is a branch node The Button, Label, and Radio button components are leaf nodes Root Node Branch Node Leaf Nodes
  • 14. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The AnchorPane is the root node The TitledPane is a child of the AnchorPane it is contained inside the AnchorPane Another AnchorPane is a child of the TitledPane it is contained inside the TitledPane The Three RadioButtons are children of the innermost AnchorPane The Button is a child of the root node AnchorPane.
  • 15. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Scene Builder to Create JavaFX Applications Scene Builder is a free design tool from Oracle for visually creating GUIs. It works like this: Use Scene Builder to construct a GUI by dragging and dropping the components that you need onto a blank window. Visually arrange the components on the window and set various component properties to create the appearance that you want for the GUI. Save the GUI to an FXML file. FXML is a markup language that describes the components in a JavaFX scene graph. FXML uses tags to organize data, in a manner similar to the way that HTML uses tags to format text in a Web browser.
  • 16. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Scene Builder to Create JavaFX Applications Visually creating a GUI with Scene Builder is only part of the process. Once you save a GUI’s scene graph to an FXML file, the next step is to write Java code that reads the FXML file and displays the GUI on the screen and handles any events that occur while the application is running.
  • 17. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Scene Builder You can download Scene Builder from the following location: www.oracle.com/technetwork/java/javafx/downloads/ When you install Scene Builder in Windows, a shortcut is automatically created on the desktop. You can launch Scene Builder either by double-clicking the shortcut, or by going to All Programs > JavaFX Scene Builder and clicking JavaFX Scene Builder x.x where x.x will be a version number such as 1.1 or 2.0 If you installed Scene Builder on a Mac, go to the Applications folder and double-click the shortcut for JavaFX Scene Builder x.x where x.x will be a version number such as 1.1 or 2.0
  • 18. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window
  • 19. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Here is a brief summary of each part of the main window: Menu Bar Scene Builder’s commands are located on the menus that access the menu bar at the top of the main window.
  • 20. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Library Panel The Library Panel provides a list of JavaFX components that you can use in an application. To place a component in a GUI, you simply drag it from the Library Panel, and drop it into the Content Panel.
  • 21. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Content Panel The Content Panel is where you visually design an application’s GUI. It initially shows an AnchorPane as the GUI’s root node. You create other components in the GUI by dragging them from the Library Panel and dropping them onto the root node component..
  • 22. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Hierarchy Panel The Hierarchy Panel shows the GUI’s scene graph. As you add components to the Content Panel, nodes appear in the Hierarchy Panel. You can use the Hierarchy Panel to select nodes that you want to edit.
  • 23. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Selection Bar This area of the screen shows the hierarchical path of the currently selected node in the scene graph.
  • 24. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window Inspector Panel The Inspector Panel is divided into three sections: Properties Layout Code
  • 25. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Scene Builder Main Window The Properties section allows you to view and edit the values of the selected component’s properties, which are values that determine the component’s appearance. The Layout section lets you specify values that control the way the component is displayed when the GUI’s window is resized. The Code section allows you to assign an fx:id to a component, which is similar to assigning a variable name to the component. also allows you to designate event handlers to execute when specific events happen to the selected component.
  • 26. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using Scene Builder to Create the Kilometer Converter GUI An AnchorPane, as the root node A Label to display the prompt Enter a distance in kilometers: A TextField in which the user will enter a distance A Label to display a message showing the distance converted to miles A Button that performs the conversion
  • 27. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Writing the Application Code Once you have saved an application’s GUI to an FXML file, you can write the Java code that runs the application. A simple JavaFX application uses: a main application class a controller class
  • 28. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Main Application Class Once you have created a GUI with Scene Builder, and saved it to an FXML file, you need to write a Java class that performs the following: Loads the FXML file Builds the scene graph in memory Displays the GUI Example: KilometerCoverter.java
  • 29. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley The Controller Class The controller class is responsible for handling events that occur while the application is running. The controller class contains the following items: The necessary import statements Private variables to reference the components that have a fx:id in the scene graph An initialize method that is automatically called after the FXML file is loaded Event listener methods Example: KilometerCoverterController.java
  • 30. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Using the Sample Controller Skeleton An alternative for manually typing the code for the controller class, Scene Builder can provide a sample "skeleton" for the controller class. To see the sample controller skeleton, click the View menu, then click Show Sample Controller Skeleton You can click the Copy button to copy the sample code to the clipboard, and then paste it into an editing window in your IDE. The obvious benefit of using the sample skeleton controller is that a lot of the code is written for you. The skeleton has all of the necessary import statements, and the class already has private field declarations for all of the components that have an fx:id. You just need to change the name of the class, and write the code for the event listener methods.
  • 31. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Summary of Creating a JavaFX Application Use Scene Builder to design the GUI. Be sure to give an fx:id to all of the components that you plan to access in your Java code. Save the GUI as an FXML file. Write the code for the main application class, which loads the FXML file and launches the application. Save and compile the code in the same location as the FXML file. Write the code for the controller class, which contains the event handler methods for the GUI. Save and compile the code in the same location as the FXML file. In Scene Builder, register the controller class, then register an event handler method for each component that needs to respond to events. Save the FXML file again.
  • 32. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley RadioButtons and CheckBoxes RadioButtons normally appear in groups of two or more and allow the user to select one of several possible options. CheckBoxes, which may appear alone or in groups, allow the user to make yes/no or on/off selections.
  • 33. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley RadioButtons RadioButtons are useful when you want the user to select one choice from several possible options. A radio button may be selected or deselected. Each radio button has a small circle that appears filled-in when the radio button is selected and appears empty when the radio button is deselected.
  • 34. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Creating a RadioButton To create a RadioButton, you simply drag it from the Library panel and drop it onto the Content panel. (The RadioButton component is found in the Controls section of the Library panel.) RadioButtons have a Text property that determines the text they display. RadioButtons normally are in a toggle group.
  • 35. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Adding RadioButtons to a Toggle Group Here are the steps for adding RadioButtons to a toggle group: Create the first RadioButton component in the Content panel. Open the Properties section of the Inspector Panel, and find the Toggle Group property. Enter the name you wish to give the toggle group. Create the next RadioButton. For its Toggle Group property, you should be able to click the down-arrow and select the toggle group that you created for the first RadioButton. Repeat this for each subsequent RadioButton that you want in the same toggle group.
  • 36. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Determining in Code Whether a RadioButton Is Selected In the controller class, you can use the RadioButton's isSelected method to determine whether the RadioButton is selected or not. The isSelected method returns a boolean value. If the RadioButton is selected, the method returns true . Otherwise, it returns false . Example: RadioButtonDemo.java, RadioButtonDemoController.java if (radio.isSelected()) { // Code here executes if the radio // button is selected. }
  • 37. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Responding to RadioButton Events In many situations you want an action to take place at the time the user clicks a RadioButton. you must write an event listener method in the controller class for each RadioButton and then select the appropriate method as the event listener in Scene Builder. Example: RadioButtonEvent.java, RadioButtonEventController.java
  • 38. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley CheckBoxes A CheckBox is a small box with text appearing next to it. Like RadioButtons, CheckBoxes may be selected or deselected at run time. When a CheckBox is selected, a small check mark appears inside the box. Although CheckBoxes are often displayed in groups, they are not usually grouped in a toggle group like RadioButtons are.
  • 39. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Creating a CheckBox To create a CheckBox, you simply drag it from the Library panel and drop it onto the Content panel. (The CheckBox component is found in the Controls section of the Library panel.) CheckBoxes have a Text property that determines the text they display.
  • 40. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Determining in Code Whether a CheckBox Is Selected In the controller class, you can use the CheckBox’s isSelected method to determine whether the CheckBox is selected or not. The isSelected method returns a boolean value. If the CheckBox is selected, the method returns true . Otherwise, it returns false . Example: CheckBoxDemo.java, CheckBoxDemoController.java if (checkbox.isSelected()) { // Code here executes if the // CheckBox is selected. }
  • 41. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Responding to CheckBox Events Sometimes you want an action to take place at the time the user clicks a CheckBox. you must write an event listener method in the controller class for the CheckBox and then select the method as the event listener in Scene Builder. Example: CheckBoxEvent.java, CheckBoxEventController.java
  • 42. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Displaying Images You can use the ImageView component to display images in an application's GUI. You simply drag the component from the Library panel (you will find it in the Controls section) and drop it onto the Content Panel Once you have created a ImageView component, you use its Image property to specify the image that it will display.
  • 43. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Displaying an Image with Code Sometimes you might need to write code that will change the image being displayed in an ImageView component, as the application is running. In your controller class, you can call the ImageView component's setImage method to do this.
  • 44. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Displaying an Image with Code First, you must create an instance of the Image class, which can read the contents of an image file. The Image class is in the javafx.scene.image package. The Image class constructor accepts a String argument that is the name of an image file. Here is an example: Image myImage = new Image("Dog.jpg"); Here is an example that uses a path. Image myImage = new Image("C:Chapter14" + "ImagesDog.jpg");
  • 45. Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Displaying an Image with Code Once you have created an Image object, you pass a reference to that object to the ImageView component's setImage method. The following is an example: Assume that myImageView references an ImageView component, and myImage references an Image object. myImageView.setImage(myImage); Example: ImageViewDemo.java, ImageViewDemoController.java