现在的位置: 首页 > 综合 > 正文

javafx.application.Application

2013年10月09日 ⁄ 综合 ⁄ 共 1963字 ⁄ 字号 评论关闭
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
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:

抱歉!评论已关闭.