Developing GUI Programs with JavaFX Framework

ee 422c java fx n.w
1 / 17
Embed
Share

"Learn about JavaFX, a framework for developing GUI programs that replaced Java Swing. Explore the structure, running a JavaFX program, stages, scenes, nodes, and more. Enhance your skills in event-driven software and MVC design pattern."

  • JavaFX
  • GUI programming
  • MVC pattern
  • event-driven
  • Java

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. EE 422C Java FX

  2. What is JavaFX? Framework for developing GUI programs Replaced Java Swing Similar conceptually to other graphics libraries EE 422C

  3. Why this JavaFX project? Learn how to use a large library without detailed instructions. Learn about event-driven software. Demonstrate the value of the MVC design pattern. Make a nice self-contained demo-able program to show off. EE 422C

  4. How to run a JavaFX program Eclipse Command Line EE 422C

  5. Basic Structure The main class for a JavaFX application extends the javafx.application.Application class. The start() method is the main entry point for all JavaFX applications (not main(), like in other Java applications). The launch(args) in main() does nothing usually. EE 422C

  6. EE 422C

  7. EE 422C

  8. Stage, Scene, Node A JavaFX application defines the user interface container by means of a stage and a scene. The JavaFX Stage class is the top-level JavaFX container. Think of it as a stage on which a play is enacted. It is a window on our screen. The JavaFX Scene class is the container for all content. Think of it as a scene in a play. Nodes are the actors to perform in the scene. EE 422C

  9. JavaFX Scene graph EE 422C

  10. Java FX Scene The Main class is an extension of the javafx.application.Application class. Its start method is overridden and receives a Stage object (a top-level GUI container) as its only parameter. The root node (in this case, an instance of the javafx.scene.Stackpane class) is created and passed to the scene's constructor, along with the scene's width, and height. The stage's title, scene, and visibility are all set. EE 422C

  11. EE 422C

  12. Coordinates The Origin is at the top left in JavaFX Y Axis (0, 0) X Axis y (x, y) (0, 0) X Axis Conventional Coordinate System Java Coordinate System Y Axis EE 422C

  13. Layout Panes JavaFX provides many types of panes for organizing nodes in a container. 13

  14. Event-Driven Programming A paradigm where the flow of the program is driven by events such as: User actions (buttons, mouse clicks, etc.) Sensor input Network traffic Messages from other programs or threads Very common in software with graphical user interfaces EE 422C

  15. Event Handler event handler is a callback subroutine that handles inputs received in a program (called a listener in Java). Each event is a piece of application-level information from the underlying framework, typically the GUI toolkit. GUI events include key presses, mouse movement, action selections, and timers expiring. Event handlers are a central concept in event- driven programming. EE 422C

  16. Event Handler EventHandler is a class that implements void handle(T event) Invoked when a specific event of the type for which this handler is registered happens. btn.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent e) { newScreen(stage); //action for button } }); //We will look at a more concise version later EE 422C

  17. Java FX program snippet class Main extends Application {} Add method start(Stage primaryStage) that works like main (String[] args) to Main Add a Scene to the primaryStage in start() Add a JavaFX Node object (such as a grid) to the Scene Add button to the Node object Add onAction code (event Handler) to the button Display the primaryStage on the computer display EE 422C

More Related Content