Eclipse writes JavaFX

Source: Internet
Author: User

(The following is a combination of multiple pages on the web.) ) What is JavaFX

JavaFX is a Java graphics and media Toolkit. It enables Java application developers to easily design and develop rich client applications (rich client application).

One thing we need to pay attention to. At the very beginning, JavaFX was published as a separate programming language, with its own SDK and its own language format (albeit close to Java). JavaFX before 2.0 is basically a scripting language. But starting with JavaFX 2.0 in October 2011, Oracle decided to publish it in the form of a Java toolkit. The advantage of this is that Java developers do not have to learn another programming language in order to develop RIA. We've seen a lot of data on JavaFX on the web still stuck in the scripting language era, and it's clear they're completely out of date.

JavaFX Configuration

If you are using JDK1.7, then the JavaFX Toolkit is already included. You just have to import it into the class library when you're developing the application. If you are using JDK 1.6, you will need to download an SDK yourself.

Example of developing JAVAFX programs using Ecilpse

Since JavaFX is now released as a Java package, we can develop JAVAFX programs in eclipse without having to install any plugins.

We used the JDK1.7.

1. Create a new Java Project. Name it JavaFX.

2. Import "Jfxrt.jar" to the class library. Right-click Addexternal JARs, Java Build Path, Libraries, Properties, JavaFX. You can find the "Jfxrt.jar" file under the "Jdk1.7.0_21/jre/lib" folder.

3. Establish the HelloWorld class.

4. Copy the following code into the Helloworld.java.

Package HelloWorld; Import Javafx.application.application;import Javafx.event.actionevent;import Javafx.event.eventhandler;import Javafx.scene.scene;import Javafx.scene.control.button;import Javafx.scene.layout.stackpane;import Javafx.stage.Stage; public class HelloWorld extends application{public   static void Main (string[] args) {       launch (args);     @Override public   void Start (Stage primarystage) {       primarystage.settitle ("Hello world!");       Button btn = New button ();       Btn.settext ("Say ' Hello World '");       Btn.setonaction (New eventhandler<actionevent> () {           @Override public           void handle (ActionEvent event) {                System.out.println ("helloworld!");           }       );              Stackpane root = new Stackpane ();       Root.getchildren (). Add (BTN);       Primarystage.setscene (new Scene (root, +));       Primarystage.show ();    }}

Let us briefly explain:

    • Application classes for JavaFX applications inherit the Javafx.application.Application class. Its start () method is the entry point for all JavaFX applications.
    • JavaFX's application interface containers are defined (stage and scene) with stage and scenes. The Stage class is located on the top level of the JavaFX container, and the Scene class is a container for all content parts (excluding borders).
    • The content of a scene in JavaFX is represented by a hierarchical node graph. In this example, the root node is the Stackpane object.
    • If you need to package JavaFX application with the JavaFX Packaging tool as a jar file, the main () method is not required. The JavaFX Packaging tool embeds a JAVAFX launcher. However, using the main () method is useful if you are not using JavaFX launcher.

Is the scenario diagram for the application:

5. OK. Our first JavaFX program is done. Click Run to try it.

Click "Say Hello World" and we'll see the output "Hello World" in the console.

Eclipse writes JavaFX

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.