javafx.application.Application

public abstract class Application
extends java.lang.Object
Application class from which JavaFX applications extend.

Life-cycle

The entry point for JavaFX applications is the Application class. (程序的入口点)The JavaFX runtime does the following, in order, whenever an application is launched:

  1. Constructs an instance of the specified Application class
  2. Calls the init() method
  3. Calls the start(javafx.stage.Stage) method
  4. Waits for the application to finish, which happens when either of the following occur:
    • the application calls Platform.exit()
    • the last window has been closed and the implicitExit attribute on Platform is true
  5. Calls the stop() method

Note that the start method is abstract and must be overridden. The init and stop methods have concrete(具体) implementations that do nothing.

Parameters

Application parameters are available by calling the getParameters() method from the init() method, or any time after the init method has been called.

Threading

JavaFX creates an application thread for running the application start method, processing input events, and running animation(动画) timelines(时间轴). Creation of JavaFX Scene and Stage objects as well as modification(修改) of scene graph operations to live objects (those objects already attached to a scene) must be done on the JavaFX application thread.

The Application constructor and init method are called on the launcher(启动器) thread, not on the JavaFX Application Thread. This means that an application must not construct a Scene or a Stage in either the constructor or in the init method. An application may construct other JavaFX objects in the init method.

Example

The following example will illustrate(演示) a simple JavaFX application.

package appliction;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class MyApp extends Application {
    public void start(Stage stage) {
        Circle circ = new Circle(40, 40, 30);
        Group root = new Group(circ);
        Scene scene = new Scene(root, 400, 300);

        stage.setTitle("My JavaFX Application");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
		launch(args);
	}
}

The above example will produce the following:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值