JAVAFX-1 Development and application

Source: Internet
Author: User

Why use JavaFX?
    • The purpose of writing this topic, in fact, is also fun, the original familiar with swing to develop Java GUI program, in fact, have already known javafx this thing, consistent no time to play, recently have time so study. This topic will refer to other existing tutorials, In combination with your own understanding of swing, there may be some places that aren't too clear.
    • A water article on swing and JavaFX https://www.zhihu.com/question/37236236
    • Existing reference article http://www.yiibai.com/javafx/javafx_overview.html

      What is JavaFX?
    • is actually the development of GUI programs, rich Internet applications are those that provide functionality similar to Web applications and can be used as a desktop application experience. They provide a better visual experience than users ' normal Web applications. These applications can be used as browser plug-ins or as virtual machines to transform traditional static applications into more enhanced, smooth, animated, and compelling applications.
    • The existing front-end technology can also do GUI programs, such as NetEase cloud Music, NetEase Youdao dictionary, etc., performance can be, but we here mainly say javafx. In fact, you are interested or can go to see the open source of NetEase to get the API system

Quickly step into the development process
    • Here we choose the idea that Eclipse likes to build learning with idea. They all provide the appropriate building plug-ins
    • Development environment:
    • Here I'm giving a direct IDE download environment, updated with Eclipse iterations
      http://downloads.efxclipse.bestsolution.at/downloads/nightly/sdk/

    • If you want to manually integrate the development environment, you can read the following article
      Http://www.yiibai.com/javafx/install-efxclipse-into-eclipse.html
    • JavaFX Scene Builder Download
      JavaFX Scene Builder is a visual layout tool that allows users to quickly design the JavaFX application user interface without coding. Users can drag and drop UI components into the workspace, modify their properties, apply style sheets, and the Fxml code for the layout they are creating will be automatically generated in the background. The result is a fxml file that can then be combined with a Java project by binding to the application's logic.
      Can be effectively integrated with Eclipse, here choose 2: Version

Address: http://www.oracle.com/technetwork/java/javase/downloads/javafxscenebuilder-1x-archive-2199384.html

    • How to integrate into eclipse
      Http://www.yiibai.com/javafx/install-javafx-scene-builder-into-eclipse.html

    • Development theory
      The deployment of the above development environment is so much, the following is about the development of basic theory, JavaFX is no longer a separate MVC development model, although essentially, how you are an understanding of the development of Android, you will soon become familiar with the development of JavaFX, they have a lot of similar places, see the following picture

Show it on the view
User Use Controller
Operation data (update, modify, delete, ...), the data on the model has changed.
Displays the model's data on the view.

    • Making Hello World
      Building the Application
  1. From the File menu, select New Project.
  2. In the JavaFX application category, select JavaFX Application and click the Next button.
  3. Name Project "HelloWorld" and click the "Finish" button.

      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 {??? @Override?? public void Start (Stage primarystage) {?????? Button btn = New button ();?????? Btn.settext ("Say ' Hello World '");?????? Btn.setonaction (New eventhandler<actionevent> () {?????????? @Override?????????? public void handle (ActionEvent Event) {?????????????? System.out.println ("Hello world!");?????????? }?????? });??????? Stackpane root = new Stackpane ();?????? Root.getchildren (). Add (btn);?????? Scene scene = new Scene (root, in.);??????? Primarystage.settitle ("Hello world!");?????? Primarystage.setscene (scene);?????? Primarystage.show ();?? }??? public static void Main (string[] args) {?????? launch (args);??}}  

    The main class of the JavaFX application needs to inherit from the Application.application class. The start () method is the entry point for all JavaFX applications.
    The JavaFX application defines the UI container as stage and scene. The stage class is the JavaFX top-level container. The scene class is a container for all content. In example 3-1, the stage and scene are created, and the scene is sized and made visible.
    In JavaFX, the content in the scene is represented by a hierarchical scene graph (scene graph) made up of the graph nodes (node). In this example, the root node is a Stackpane object, which is a resizable layout node. This means that when the user changes the stage size, the root node can change depending on the size of the scene.
    The root node contains a button child node with text, and an event Handler is added to the button, which outputs information to the console when the button is clicked.
    The main () method is not required when the JavaFX application is packaged with the JavaFX Packager tool, because the JavaFX package tool embeds JavaFX launcher in the jar file. However, it is still useful to keep the main () method so that you can run a jar file without JavaFX launcher, such as when using some Ides that are not fully integrated with JavaFX tools. Another swing application that embeds the JavaFX code still needs the main () method.

    • Run effect

JAVAFX-1 Development and application

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.