0

目前,我有一种临时的方式来访问我的 Java 代码调用的 FXML 文件和 CSS 文件。

为了访问我的 CSS 文件,我将它们放在我的bin文件夹中,并通过我的 FXML 文件中的引用访问它,如下所示。

<fx:root type="javafx.scene.layout.AnchorPane" prefHeight="600.0" prefWidth="800.0" xmlns:fx="http://javafx.com/fxml" stylesheets="splashStyle.css">

为了访问我的 FXML 文件,我将它们存储在我的.class文件所在的任何位置,并按如下方式访问它们。

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("splashLayout.fxml"));

所以我很好奇在存储和访问方面有更好的方法来做到这一点,因为刚才看起来非常不一致和不专业。

谢谢!:)

4

1 回答 1

0

我认为最好的做法是将资源存储在一个文件夹中,如:src/main/resources 作为 maven 项目布局建议(参见:http ://maven.apache.org/guides/introduction/introduction-to-the-standard-directory -layout.html

要访问它们,请参见:http ://docs.oracle.com/javase/1.5.0/docs/guide/lang/resources.html

或者这个:如何在 jar 文件中使用 ClassLoader.getResources()

于 2012-12-06T17:22:21.523 回答