Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 14 JavaFX Basics Dr. Clincy - Lecture.

Similar presentations


Presentation on theme: "Chapter 14 JavaFX Basics Dr. Clincy - Lecture."— Presentation transcript:

1 Chapter 14 JavaFX Basics Dr. Clincy - Lecture

2 Java GUI Programming What is a graphical user interface (GUI) ? And what is GUI programming ? When Java was initially introduced, the GUI classes were bundled in a library known as the Abstract Windows Toolkit (AWT). AWT is fine for developing simple GUIs, but not good for developing comprehensive GUI projects. In addition, AWT is prone to platform-specific bugs. Later, the AWT was replaced by a more robust, versatile, and flexible library known as Swing components. Swing components depend less on the target platform and use less resources. With the release of Java 8, Swing is replaced by a completely new GUI platform known as JavaFX. JavaFX is a newer framework for developing Java GUI programs. Dr. Clincy - Lecture

3 Basic Structure of JavaFX
javafx.application.Application class defines the essential framework for writing JavaFX programs Every JavaFX program is defined in a class that extends javafx.application.Application Stage object is automatically created by JVM when the application is launched – considered the window – you can have multiple stages. Scene object is the container for the content – considered the frame in the window – can have only one scene per stage or window Button object (or node) is a visual component such as a shape, image, UI control, groups, and panes. Used to invoke some type of action Container classes called panes can be used to help layout the nodes within a scene. Control refers to a label, check box, radio button, text field and etc. A group can be used to group a set of nodes Dr. Clincy - Lecture

4 Panes, UI Controls, and Shapes
( 1 ) One Scene per Stage ( 2 ) A Scene can contain a Control, Group or Pane ( 3 ) A Pane or Group can contain any subtype of Node ( 4 ) Will cover the various types of Panes later Dr. Clincy - Lecture

5 Basic Structure of JavaFX Program
Every JavaFX program extends javafx.application.Application The main class overrides the start method defined in javafx.application.Application and JVM constructs an instance of the class and invoke the start method. Create a button object and places it in a Scene object Scene object created using the constructor – specifies width and height and places node in scene The Stage object is automatically created by JVM when the app is launched Name the Stage, set the scene in the stage, and display the stage. The launch method is static method used for launching stand-alone JavaFX apps. Not needed if you run it from a command line. Output of program displays a button in the window Dr. Clincy - Lecture

6 JavaFX Program w/Multiple Stages
Every JavaFX program extends javafx.application.Application The main class overrides the start method defined in javafx.application.Application and JVM constructs an instance of the class and invoke the start method. The first Scene object is created using the constructor – specifies width and height and places button in scene The first Stage object is automatically created by JVM when the app is launched Name the first Stage, set the scene in the stage, and display the stage. A new stage is created. Name the second Stage, set the scene in the stage, places button in Scene, and display the stage. The launches JavaFX app. Identical main method for all every JavaFX app. Output of program displays multiple stages Dr. Clincy - Lecture

7 JavaFX Program w/Stage within Stage
Every JavaFX program extends javafx.application.Application The main class overrides the start method defined in javafx.application.Application and JVM constructs an instance of the class and invoke the start method. The first Scene object is created using the constructor – specifies width and height and places button in scene (200 and 250) Name the second Stage, set the scene in the stage, places button in Scene, and display the stage. The second Scene object is created using the constructor – specifies width and height and places button in scene (100 and 100) Output of program displays overlapping stages Dr. Clincy - Lecture

8 JavaFX Program w/Button in Pane
For Pane Create a Pane Add button to created Pane Add Pane to Scene Name the Stage, set the scene in the stage, and display the stage. Output of program displays a button in the center of the pane Lines 11 and 12 could be replaced with: StackPane pane = new StackPane (new Button(“OK”)); Dr. Clincy - Lecture

9 JavaFX Program w/Circle in Pane
For Circle and Color Create a Circle Set Circle properties Set Circle’s center at (100,100) Measurements are in pixels The color of the circle The color of the circle’s fill Create Pane and add Circle Add Pane to Scene Output of program displays a circle in the center of the scene Dr. Clincy - Lecture

10 Positioning a Shape Java’s Approach Conventional Approach
Dr. Clincy - Lecture

11 Cover Lab 9 Dr. Clincy - Lecture


Download ppt "Chapter 14 JavaFX Basics Dr. Clincy - Lecture."

Similar presentations


Ads by Google