gpt4 book ai didi

Java 12.0.1 中的 JavaFX

转载 作者:行者123 更新时间:2023-12-02 01:29:40 24 4
gpt4 key购买 nike

我无法让 OpenJFX 在我的项目中工作。我将该库导入到我的 IntelliJ 项目中,它解决了所有构建错误,但是当我启动程序时什么也没有发生。控制台没有给我任何输出。程序启动,然后无限期运行,不显示任何内容。当我停止程序时,它说进程已完成,退出代码为130(被信号2中断:SIGINT)

Main.java

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {
public static void main(String[] args) {
}

@Override
public void start(Stage stage) throws Exception {
stage.setTitle("Binary Clock");
stage.setScene(new Scene(FXMLLoader.load(getClass().getResource("clock_gui.fxml"))));
stage.show();
}
}

clock_gui.fxml(由 SceneBuilder 创建)

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.Rectangle?>


<AnchorPane prefHeight="276.0" prefWidth="344.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ClockGui">
<children>
<HBox layoutX="100.0" layoutY="125.0" spacing="4.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<VBox id="hour_tenner" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="ht8" fx:id="ht8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="ht4" fx:id="ht4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="ht2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="ht1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
</children>
</VBox>
<VBox id="hour_single" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="hs8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="hs4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="hs2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="hs1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
</children>
</VBox>
<VBox id="minute_tenner" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="mt8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="mt4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="mt2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="mt1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
</children>
</VBox>
<VBox id="minute_single" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="ms8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="ms4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="ms2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
<Rectangle id="ms1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="64.0" stroke="BLACK" strokeType="INSIDE" width="64.0" />
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="4.0">
<children>
<Button fx:id="start" mnemonicParsing="false" onMouseClicked="#ClockGui" prefHeight="30.0" prefWidth="64.0" text="start">
<VBox.margin>
<Insets bottom="102.0" />
</VBox.margin>
</Button>
<HBox prefHeight="100.0" prefWidth="200.0" spacing="4.0">
<children>
<VBox id="second_tenner" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="st8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="st4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
<Rectangle id="st2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
<Rectangle id="st1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
</children>
</VBox>
<VBox id="second_single" prefWidth="50.0" spacing="4.0">
<children>
<Rectangle id="ss8" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0">
<VBox.margin>
<Insets />
</VBox.margin>
</Rectangle>
<Rectangle id="ss4" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
<Rectangle id="ss2" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
<Rectangle id="ss1" arcHeight="5.0" arcWidth="5.0" fill="DODGERBLUE" height="30.0" stroke="BLACK" strokeType="INSIDE" width="30.0" />
</children>
</VBox>
</children>
</HBox>
</children>
</VBox>
</children>
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
</HBox>
</children>
</AnchorPane>

ClockGui.java(作为 Controller )

import javafx.fxml.FXML;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

public class ClockGui {

@FXML
private Rectangle ht8;

public ClockGui(){
ht8.setFill(Color.rgb(225,250,30));
}
}

我使用的是 Ubuntu 18.04.2 LTS。

最佳答案

你说你启动了虚拟机,但它“什么也没做”。其原因在于您的主要内容:

public static void main(String[] args) {
}

这是您的应用程序的入口点,但您并没有要求它调用您的应用程序类...

正如您从 (Javadoc]( https://openjfx.io/javadoc/12/javafx.graphics/javafx/application/Application.html#launch(java.lang.String...) ) 中读到的,这是启动独立应用程序所需的方法,通常从 main 调用。

只需添加以下内容:

public static void main(String[] args) {
launch(args);
}

然后再次运行。

关于Java 12.0.1 中的 JavaFX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56307106/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com