1.类要继承于javafx.application.Application
2.实现start()方法,这是应用程序的入口
import javafx.application.Application;
import javafx.stage.Stage;
public class App extends Application{
public void start(Stage primaryStage){
primaryStage.setTitle("hello");//设置标题
primaryStage.show();
}
public static void main(String[] args){
launch(args);
}
}
其中main在程序中非必要
程序运行结果:
添加文本:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class main extends Application{
public void start(Stage primaryStage){
Text t = new Text("Hello World");
StackPane stackPane = new StackPane();
stackPane.getChildren().add(t);
Scene scene = new Scene(stackPane,400,300);
primaryStage.setScene(scene);
primaryStage.setTitle("hello");
primaryStage.show();
}
public static void main(String[] args){
launch(args);
}
}
运行结果: