Lesson 9 GUI in Java
Lesson 9 GUI in Java
educba.com
Chapter 15
15.1 Introduction
15.2 Scene Graphs
15.3 Using Scene Builder to Create JavaFX Applications
15.4 Writing the Application Code
15.5 RadioButtons and CheckBoxes
15.6 Displaying Images
15.1 Introduction
• FXML uses tags to organize data, in a manner similar to the way that HTML
uses tags to format text in a Web browser.
15.3 Using Scene Builder to Create JavaFX
Applications (2 of 2)
www.oracle.com/technetwork/java/javafx/downloads/
Example: KilometerCoverterController.java
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.
Summary of Creating a JavaFX Application
Example: ImageViewDemo.java,
ImageViewDemoController.java
Chapter 12
• We use these constants later in the program to set the size of the
window.
• The window’s size is measured in pixels.
• A pixel (picture element) is one of the small dots that make up a
screen display.
12.2 Creating Windows (5 of 7)
• An instance of the JFrame class needs to be created:
• This statement:
– creates a JFrame object in memory and
– assigns its address to the window variable.
• The string that is passed to the setTitle method will appear in
the window’s title bar when it is displayed.
• To specify the action to take place when the user clicks on the
close button.
• Examples: KiloConverter.java
Handling Action Events (1 of 4)
• An event is an action that takes place within a program, such
as the clicking of a button.
• When an event takes place, the component that is responsible
for the event creates an event object in memory.
• The event object contains information about the event.
• The component that generated the event object is know as the
event source.
• It is possible that the source component is connected to one or
more event listeners.
Handling Action Events (2 of 4)