我在raspberrypi3上使用Java fx运行了jar文件,但未输出背景图像gif

时间:2019-03-04 17:26:31

标签: java javafx raspberry-pi3

通常在桌面上输出背景图像,但在树莓派上不输出背景图像。

public class Main extends Application {
@Override
public void start(Stage stage)throws IOException {
    Parent root=FXMLLoader.load(getClass().getResource("prototype.fxml"));

    stage.setScene(new Scene(root));
    stage.setMaximized(true);
    stage.setTitle("Prototype");
    stage.show();
}

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

这是我的Javafx Controller.java的代码

public class Controller implements Initializable{
    @FXML private StackPane background;

    File five=new File("/home/pi/Desktop/image/snow.gif");

    private Image snow=new Image(five.toURI().toString());

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        Thread thread = new Thread() {
            @Override
            public void run() {
                while(true) {
                    Platform.runLater(()->{
                        BackgroundImage e=new BackgroundImage(snow,BackgroundRepeat.NO_REPEAT, BackgroundRepeat.NO_REPEAT, BackgroundPosition.CENTER,new BackgroundSize(BackgroundSize.AUTO, BackgroundSize.AUTO, true, true, true, true));
                        background.setBackground(new Background(e));
                    });
                    try {Thread.sleep(1000);}catch(InterruptedException e) {}
                }
            };
        };
        thread.setDaemon(true);
        thread.start();
    };

}

这是由场景构建器编写的xml。

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

<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<StackPane fx:id="background" maxHeight="500.0" maxWidth="1000.0" minHeight="250.0" minWidth="500.0" prefHeight="500.0" prefWidth="1000.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
   <children>
      <GridPane alignment="CENTER" maxHeight="250.0" maxWidth="300.0" minHeight="50.0" minWidth="50.0" prefHeight="254.0" prefWidth="276.0" rotate="180.0" style="-fx-background-color: #ffffff; -fx-background-color: rgba(255,255,255,0.5); -fx-background-radius: 50;" StackPane.alignment="CENTER">
         <children>
            <Label fx:id="watch" alignment="CENTER" style="-fx-font-size: 60;" text="Time" />
            <Label fx:id="weeken" style="-fx-font-size: 30;" text="Week" GridPane.rowIndex="1" />
            <Label fx:id="weathering" style="-fx-font-size: 30;" text="Weathing" GridPane.rowIndex="2" />
         </children>
         <columnConstraints>
            <ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
         </columnConstraints>
         <rotationAxis>
            <Point3D y="1.0" />
         </rotationAxis>
         <rowConstraints>
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
            <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
         </rowConstraints>
      </GridPane>
   </children>
</StackPane>

它是原始程序的一部分。我需要将天气数据转换为gif背景图像。但是不输出图像。我需要帮助。

0 个答案:

没有答案