我該如何解決這個問題,一個空白的窗口上運行的項目空白窗口的JavaFX
打開,這是我的主:
package application;
import java.io.IOException;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
public class Main extends Application {
private Stage primaryStage;
@Override
public void start(Stage primaryStage) {
this.primaryStage = primaryStage;
primaryStage.show();
}
public void mainWindow() {
try {
FXMLLoader loader =new FXMLLoader(Main.class.getResource("/MainWindowView.fxml"));
AnchorPane pane = loader.load();
MainWindowController mainWindowController = loader.getController();
mainWindowController.setMain(this);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
這是我的看法XML:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane prefHeight="1080.0" prefWidth="1920.0"
xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="application.MainWindowController">
<children>
<Label fx:id="label" alignment="CENTER" layoutY="420.0" text="Label" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<font>
<Font size="71.0" />
</font>
</Label>
<HBox alignment="CENTER" layoutX="774.0" layoutY="540.0" spacing="20.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
<children>
<TextField layoutX="774.0" layoutY="540.0" />
<Button layoutX="1268.0" layoutY="540.0" mnemonicParsing="false" onAction="#handleButton" text="Click Me!" />
</children>
</HBox>
</children>
</AnchorPane>
和這是我的控制器:
package application;
import java.awt.Label;
import java.awt.TextField;
import javafx.fxml.FXML;
public class MainWindowController {
@FXML private Label label;
@FXML private TextField field;
private Main main;
public void setMain(Main main) {
this.main = main;
}
public void handleButton() {
String text = field.getText();
label.setText(text);
}
}
這個鏈接有一個鏈接到所有這三個代碼在hastebin如果想要這樣看待(https://pastebin.com/raw/hbGBJUng),即時通訊新的java和javafx,我不知道我在做什麼錯誤,因爲當我在日食中運行項目向我展示了一個空窗口,因爲當我在scenebuilder中打開xml時,我添加了一個按鈕,一個標籤和一個文本字段。