JavaFx introductory tutorial (1)

What is JavaFx?

In fact, it can be understood as using java to do desktop programs.

Development environment installation

1. Use the plugin in eclipse
2. Use the NetBeans IDE tool

Here is an example of NetBeans. Before
installing NetBeans, make sure that JDK has been installed on the computer.
Go to the official website to download:
Official download address

Download NetBeans IDEs

Choose your own corresponding system, and download the simplest version of java SE here.

The first JavaFx program

After the installation is successful, you can create a new project to develop the
file - the new project is as shown below
Create a new javafx project

Click Next - Finish

Right-click the project and click Run to run your first javafx project as shown below
run your first javafx project

Javafx code structure

OK the first javafx operation is completed, let's take a look at their code structure

javafx code structure

As shown in the figure
, Demo.java inherits Application and implements the main method. Here is the entry of the program.
demoFxml.fxml is the layout file
demoFxmlController is the logical processing of the corresponding layout file

layout

At this point, we open the fxml file and find that there is no visual interface. Next, we need to download a tool JavaFX Scene Builder Visual interface editor
JavaFX Scene Builder download address

JavaFX Scene Builder

Then open the fxml file and drag the controls to edit your own interface.

JavaFX project packaging

javafxpackager -deploy -native image -outdir packages -outfile HelloWorld -srcdir . -srcfiles HelloWorld.jar -appclass helloworld.HelloWorld

First you need to have the compiled output jar file of your project. If you are using NetBeans IDE, go to your JavaFX project folder /dist folder and find the jar file (eg HelloWorld.jar), you can copy it to another folder, or package it in this folder. In short, Windows cmd enters the folder where the HelloWorld.jar is located, and entering the above command will generate the following file folder

The next article will write a small demo written by myself

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325810199&siteId=291194637