【发布时间】:2020-03-27 05:42:23
【问题描述】:
我是 Eclipse java、Gradle 和 Javafx 的新手。最近我正在尝试用 gradle 项目编写一个 javafx 应用程序。以下是我想提供的各种细节。
Javafx SDK version and location
Scene Builder version and location
我的问题在这里也引起了,填充实际上是如何在 Eclipse 中工作的?我应该在哪里放置驱动程序类?在 src/main/java 下?
这就是我格式化我的用户界面的方式。
ui.fxml:
> <?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.171">
<children>
<Button fx:id="button1" layoutX="-317.0" layoutY="-145.0" mnemonicParsing="false" onAction="#buttonPressed" text="Hit me" />
<Label fx:id="label1" layoutX="66.0" layoutY="-98.0" text="hi" />
</children>
</AnchorPane>
build.gradle
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.8'
}
repositories {
mavenCentral()
}
dependencies {
modules = [ 'javafx.controls', 'javafx.fxml' ]
version = "11.0.2"
}
mainClassName = 'Library'
我怀疑这里有一些问题,因为当我运行 gradle 项目时,我无法运行它。我只能构建它。
Library.java:(驱动类)
public class Library {
public static void main(String arg[]) {
ex2.UIApplication.run(arg);
}
}
当我运行它时,我遇到了很多错误。
Error: Could not find or load main class Lab_3_1.Library
Lab3Controller.java:
package ex2;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
public class Lab3Controller {
@FXML
private Button button1;
@FXML
private Label label1;
@FXML
void buttonPressed(ActionEvent event) {
}
}
UIApplication.java:
package ex2;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class UIApplication extends Application{
@Override
public void start(Stage stage) throws Exception{
FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("/ui.fxml"));
VBox root = (VBox) loader.load();
Scene scene = new Scene(root);
stage.setScene(scene);
stage.setTitle("Lab 3");;
stage.show();
}
public static void run (String arg[]) {
Application.launch(arg);
}
}
【问题讨论】:
标签: java eclipse gradle javafx