Joe*_*gan 4 java eclipse macos javafx
每当我在 Eclipse 中创建项目并包含 javafx 时,单击运行按钮时应用程序都不会加载。
例如
package test;
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;
public class test extends Application {
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) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
这应该运行一个简单的 hello world 应用程序,取自 oracle 文档。但是,当我“运行”此代码时,没有打开任何窗口。而是打开一个名为“java”的应用程序。看起来'java'只是一个位于'jdk1.8.0_25.jdk/contents/home/bin'中的'unix可执行文件'。应用程序“java”完全不显示任何内容,如果不强制退出就无法关闭。
我在 Macbook 上运行 eclipse。我可能遗漏了一些重要的细节......
有谁知道为什么我的应用程序没有正常运行?原谅我的天真,我是java和eclipse的新手。
非常感谢
编辑:
import javafx.application.Application;
import javafx.stage.Stage;
public class JavaFX extends Application {
public static void main(String[] args){
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
// TODO Auto-generated method stub
stage.show();
}
}
Run Code Online (Sandbox Code Playgroud)
这个简单的程序也给出了同样的错误。
| 归档时间: |
|
| 查看次数: |
6264 次 |
| 最近记录: |