尝试创建JavaFX应用程序。 不要添加或修改任何代码。 运行项目。它找不到MAIN。 如果您运行文件,那么它将起作用。
但是,创建JavaFX FXML应用程序。如前所述,请不要对代码进行任何更改。
运行程序包...。它起作用。
有人知道为什么吗?我试图报告这个问题,但是看起来比编写代码要复杂得多。 :)
我附上了JAVAFX APPLICATION生成的代码
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package forsubmission;
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;
/**
*
* @author Hornigold
*/
public class ForSubmission 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, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
谢谢, 黄金