Mooc.fi 第 13 部分 图形用户界面 - 如何让 JavaFX 工作

问题描述 投票:0回答:1

我还没有设法让 JavaFX 工作,因此我陷入了第 13 部分图形用户界面我的第一个应用程序(https://java-programming.mooc.fi/part-13/1-graphical-user-interfaces) .

我环顾四周,但没有找到任何可以让它发挥作用的东西。首先,我从 https://gluonhq.com/products/javafx/ 下载了 JavaFX,然后按照 https://ohjelmointi-20.mooc.fi/javafx-ohjeet 但它不起作用,随后我尝试了按照我在其他线程中读到的内容进行操作。似乎其他人以前也遇到过这样的问题,但如果有一些关于如何正确配置的说明,那就太好了。

其他一些线程似乎有人问过这个问题:https://www.reddit.com/r/learnjava/comments/nb2nrb/mooc_part_13_gui_cant_figure_out_how_to_connect/ https://www.reddit.com/r/learnjava/comments/hl49y2/moocfi_part_13_and_openjfx/ https://www.reddit.com/r/learnjava/comments/mrv4fq/javafx_sdk_or_jmods_for_moocfi/ 有谁能够帮助解决这个问题,或者提供任何线索,告诉我需要修复什么才能使其正常工作?我这边将非常感激。

这就是我的 POM 文件的依赖项和插件部分当前的样子:

`<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>fi.helsinki.cs.tmc</groupId>
            <artifactId>edu-test-utils</artifactId>
            <version>0.4.2</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-junit</artifactId>
            <version>4.0.15-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>testfx-core</artifactId>
            <version>4.0.15-alpha</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.testfx</groupId>
            <artifactId>openjfx-monocle</artifactId>
            <version>8u76-b04</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>11</version>
        </dependency>
    </dependencies>
   
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.6.0</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.1</version>
                <configuration>
                    <argLine>-Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>fi.helsinki.cs.tmc</groupId>
                <artifactId>runner-maven-plugin</artifactId>
                <version>1.0.1</version>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.3</version>
                <configuration>
                    <release>${maven.compiler.release}</release>
                    <launcher>launcher</launcher>
                    <mainClass>myFirstApplication.MyFirstApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>`

当我运行测试时,我收到错误:

运行时异常:未找到工具包 没有找到工具包 com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:272) com.sun.javafx.application.PlatformImpl.isFxApplicationThread(PlatformImpl.java:401) javafx.application.Platform.isFxApplicationThread(Platform.java:182)

我已经安装并配置了 Java FX,根据我看到的其他遇到相同问题的人使用的内容编辑 POM(请参阅上面的链接)。

java netbeans sdk pom.xml
1个回答
0
投票

尝试使用 AdoptOpenJDK 版本 11。 因此,请前往 https://adoptopenjdk.net 并下载该 Java 版本。然后更改您的项目结构以使用 AdoptOpenJDK。

© www.soinside.com 2019 - 2024. All rights reserved.