JavaFX в Java 12.0.1 - PullRequest
       20

JavaFX в Java 12.0.1

0 голосов
/ 25 мая 2019

Я не могу заставить 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.

1 Ответ

2 голосов
/ 25 мая 2019

Вы говорите, что запускаете виртуальную машину, но она ничего не делает.Причина этого кроется в вашем основном:

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);
}

и беги снова.

...