我想知道如何使用JavaFX从Windows shell编译代码.
我有这个代码fxservidor.java:
public class Fxservidor extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Synthetizer os = new Synthetizer("Ximena");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
Run Code Online (Sandbox Code Playgroud) 我一直按照说明使用 Java JDK 15 和 JavaFX 15 构建 Hello World JavaFX 应用程序。我添加了此处描述的运行配置:https: //openjfx.io/openjfx-docs/#IDE-Eclipse。当我在 Mac 上运行该程序时,我的控制台中没有收到任何错误,但 GUI 没有出现。在我的 Windows 计算机上构建相同的应用程序,我能够构建并查看 GUI。
主程序.java
package hellofx;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("hellofx.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 400, 300));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Run Code Online (Sandbox Code Playgroud)
控制器.java
package hellofx;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
public class Controller {
@FXML …Run Code Online (Sandbox Code Playgroud)