有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java JavaFX项目未显示

下面是为我正在进行的一个项目启动JavaFXGUI的代码。然而,当我去执行这些类时,它被卡住了。它打印的所有内容都是启动MCPY GUI,然后坐在那里。有什么帮助吗

发射器类

public class MCPY {
    public static void main(String args[]) {
        System.out.println("Starting MCPY GUI...");   
        Main.main(args);
    }
}

主要的

package com.mcpy.gui;

import java.io.IOException;

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

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        FXMLLoader loader = new FXMLLoader(getClass().getResource("styles/Main.fxml"));
        Parent root;

        try {
            root = loader.load();
        } catch (IOException ioe) {
            // log exception
            return;
        }

        //init the connection to the controller class
        MainController MainController = loader.getController();
        MainController.setMain(this);

       //load the scene
       primaryStage.setTitle("Minecraft Launcher Python");
       primaryStage.setScene(new Scene(root, 800, 500));
       primaryStage.show();

    };


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

梅因。FXML


<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.image.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.control.Button?>

<TitledPane animated="false" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" text="Minecraft Launcher Python Login Screen" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.mcpy.gui.MainController">
    <content>
        <AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
            <children>
                <ImageView fitHeight="135.0" fitWidth="119.0" layoutX="14.0" layoutY="14.0" pickOnBounds="true" preserveRatio="true">
                    <image>
                    </image>
                </ImageView>
                <Button id="play" layoutX="231.0" layoutY="176.0" mnemonicParsing="false" onAction="#playButtonActionEvent" text="Play" />
                <Button id="login" layoutX="313.0" layoutY="176.0" mnemonicParsing="false" onAction="#loginButtonEvent" text="Login" />
                <Button id="create_account" layoutX="77.0" layoutY="176.0" mnemonicParsing="false" onAction="#create_accountButtonEvent" text="Create Account" />
            </children></AnchorPane>
    </content>
</TitledPane>

主控制器

package com.mcpy.gui;


import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;

import com.mcpy.gui.Play;
import com.mcpy.gui.Login;
import com.mcpy.gui.CreateAccount;
/* Logic for the main gui. DO NOT EDIT. */
public class MainController {

    @SuppressWarnings("unused")
    private Main main;

    public void setMain(Main main) {
        this.main = main;

    }
    @FXML
    private static Button login;

    @FXML
    private static Button create_account;

    @FXML 
    private static Button play;

    @FXML
    public void loginButtonEvent(ActionEvent lbe) {
        String[] args = (null);        
        Login.main(args);
    };

    @FXML    
    public void create_accountButtonEvent(ActionEvent cabe) {
        String[] args = (null);          
        CreateAccount.main(args);
    };

    @FXML    
    public void playButtonActionEvent(ActionEvent pbae) {       
        Play.play_mc();
    }
}

所有代码都在这里。启动器(MCPY.java)主gui及其相应的控制器和样式表(main.java、MainController.java和main.FXML)

编辑:我已经应用了@naimdjon建议的FXML更改,但是单击按钮时会产生以下错误:https://pastebin.com/8EV9wfnm


共 (0) 个答案