JavaFX in Java 12.0.1



我无法让OpenJfx在我的项目中工作。我将库将库导入到我的Intellij项目中,并解决了所有构建错误,但是当我启动程序时,什么也不会发生。该控制台没有给我任何输出。该程序启动然后不确定地运行,而无需显示任何内容。当我停止程序时,它说Process finished with exit code 130 (interrupted by signal 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(作为控制器(

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上。

您说您启动了VM,但它"无"。原因是您的主要原因:

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

这是您申请的切入点,但您不要求它致电您的应用程序类...

您可以从(javadoc](https://openjfx.io/javadoc/12/javafx.graphics/javafx/javafx/application/application/application.html#launch(java.lang.string ...((,(,(,(,这是启动独立应用程序的必需方法,通常从main调用。

只要添加以下内容:

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

再次运行。

最新更新