{"id":1405,"date":"2017-08-07T16:51:23","date_gmt":"2017-08-07T16:51:23","guid":{"rendered":"http:\/\/www.testingdocs.com\/questions\/?p=1405"},"modified":"2021-03-21T06:14:36","modified_gmt":"2021-03-21T06:14:36","slug":"what-is-javafx-api","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/what-is-javafx-api\/","title":{"rendered":"What is JavaFX API?"},"content":{"rendered":"<article id=\"post-1710\" class=\"post clearfix post-1710 type-post status-publish format-standard hentry category-java-automation has-post-title no-post-date has-post-category no-post-tag no-post-comment no-post-author \">\n<div class=\"post-content\">\n<div class=\"entry-content\">\n<h3><strong>JavaFX API<\/strong><\/h3>\n<p>JavaFX API is used for creating GUI rich desktop applications also called as Rich internet applications (RIAs). It is a set of Java libraries designed to enable you to create and deploy rich client applications that have rich UI controls. It can be used to create graphical user interfaces for many platforms.<\/p>\n<p>I will use BlueJ Editor to create a sample class. Create a new Java Class Main and choose the option JavaFX class.<\/p>\n<h3>Sample JavaFX class<\/h3>\n<pre>public class Main extends Application\r\n{\r\n    \/\/ We keep track of the count, and label displaying the count:\r\n    private int count = 0;\r\n    private Label myLabel = new Label(\"0\");\r\n\r\n    @Override\r\n    public void start(Stage stage) throws Exception\r\n    {\r\n        \/\/ Create a Button or any control item\r\n        Button myButton = new Button(\"Click to Increase Count\");\r\n\r\n\/\/ Create a new grid pane\r\n        GridPane pane = new GridPane();\r\n        pane.setPadding(new Insets(10, 10, 10, 10));\r\n        pane.setMinSize(300, 300);\r\n        pane.setVgap(10);\r\n        pane.setHgap(10);\r\n\r\n\/\/set an action on the button using method reference\r\n        myButton.setOnAction(this::buttonClick);\r\n\r\n\/\/ Add the button and label into the pane\r\n        pane.add(myLabel, 1, 0);\r\n        pane.add(myButton, 0, 0);\r\n\r\n\/\/ JavaFX must have a Scene (window content) inside a Stage (window)\r\n        Scene scene = new Scene(pane, 300,100);\r\n        stage.setTitle(\"Simple JavaFX Application\");\r\n        stage.setScene(scene);\r\n\r\n\/\/ Show the Stage (window)\r\n        stage.show();\r\n    }\r\n\r\n    \/**\r\n     * This will be executed when the button is clicked\r\n     * It increments the count by 1\r\n     *\/\r\n    private void buttonClick(ActionEvent event)\r\n    {\r\n        \/\/ Counts number of button clicks and shows the result on a label\r\n        count = count + 1;\r\n        myLabel.setText(Integer.toString(count));\r\n        System.out.println(\"You have clicked the button\");\r\n    }\r\n}\r\n\r\n<\/pre>\n<h3><strong>Application class<\/strong><\/h3>\n<pre>The Application class is the primary class for the JavaFX applications. It is the entry point for the application. for example (start methods ).\r\n\r\n<\/pre>\n<pre>public class SampleFXApp extends Application {\r\n\r\n    public void start(Stage stage) {\r\n\r\n   .\r\n\r\n   .\r\n\r\n   .\r\n\r\n    }\r\n\r\n}\r\n\r\n<\/pre>\n<p>The Scene , Stage are top level classes that acts like containers for all content in a scene. Containers hold other class objects ( like Buttons , Menu, controls etc)<\/p>\n<p>To run the application, right click on the class and choose Run JavaFX Application.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1712\" src=\"http:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Simple-JavaFX-Application.png\" alt=\"Simple JavaFX Application\" width=\"1159\" height=\"593\" title=\"\"><\/p>\n<div id=\"themify_builder_content-1710\" class=\"themify_builder_content themify_builder_content-1710 themify_builder\" data-postid=\"1710\"><\/div>\n<\/div>\n<\/div>\n<\/article>\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-1405\" data-postid=\"1405\" class=\"themify_builder_content themify_builder_content-1405 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>JavaFX API JavaFX API is used for creating GUI rich desktop applications also called as Rich internet applications (RIAs). It is a set of Java libraries designed to enable you to create and deploy rich client applications that have rich UI controls. It can be used to create graphical user interfaces for many platforms. I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[],"class_list":["post-1405","post","type-post","status-publish","format-standard","hentry","category-java","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1405","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=1405"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1405\/revisions"}],"predecessor-version":[{"id":19714,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/1405\/revisions\/19714"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=1405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=1405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=1405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}