JavaFx 阶段未出现

标签 java javafx

我正在尝试显示一个舞台,但似乎没有任何内容正在加载。编译它没有显示任何错误,但不会加载任何内容。任何帮助表示赞赏!谢谢! :) 其中最重要的部分是,当运行 JavaFX 时,没有加载任何内容。完全没有。我真的不明白这个程序出了什么问题。

package EventClick;


/**
 * Write a description of class databaseq here.
 *
 * @author (your name)
 * @version (a version number or a date)
 */
import EventClick.adminLogin.*;
import javafx.application.*;
import javafx.stage.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.geometry.*;
import java.util.*;
import javafx.util.Duration;
import javafx.animation.PauseTransition;

public class databaseq extends Application {
    Stage stage;
    Stage stage2;

    @Override public void start(Stage primaryStage) {
        stage = primaryStage;
        Platform.setImplicitExit(false);
        //Create Login Button
        Button loginbtn = new Button();
        loginbtn.setText("Login");
        loginbtn.setOnAction(e -> loginOn_Click());

        //Create Credentials Button
        Button credbtn = new Button();
        credbtn.setText("Credentials");
        credbtn.setOnAction(e -> credOn_Click());

        //Create Close Button
        Button closebtn = new Button();
        closebtn.setText("Quit");
        closebtn.setOnAction(e -> closeOn_Click());
        //Add buttons to a layout pane
        VBox pane = new VBox(10);
        pane.getChildren().addAll(loginbtn, credbtn, closebtn);
        pane.setAlignment(Pos.CENTER);

        //Add layout pane to a scene
        Scene scene = new Scene(pane, 250, 150);
        Scene scene2 = new Scene(pane, 250, 150);
        //Finish and show the scene

        primaryStage.setScene(scene);
        primaryStage.setTitle("Test Server");
        primaryStage.show();
    }

    public void loginOn_Click() {
       Alert a = new Alert(Alert.AlertType.CONFIRMATION,"Do you want to log in?",
                                                        ButtonType.YES, ButtonType.NO);        
        Optional<ButtonType> confirm = a.showAndWait();
        if(confirm.isPresent() && confirm.get() == ButtonType.YES) {

        }
    }
    public void credOn_Click() {
        Alert a = new Alert(Alert.AlertType.INFORMATION);
        a.setTitle("Test Server");
        a.setHeaderText("Loading Credentials...");
        a.setContentText("Entering User Login Server");

        a.showAndWait();
    }

    public void closeOn_Click() {
        Alert a = new Alert(Alert.AlertType.CONFIRMATION,"Are you sure you want to quit?",
                                                        ButtonType.YES, ButtonType.NO);
        Optional<ButtonType> confirm = a.showAndWait();
        if(confirm.isPresent() && confirm.get() == ButtonType.YES) {
            stage.close();
        }
    }
}

最佳答案

 //Add layout pane to a scene
    Scene scene = new Scene(pane, 250, 150);
    Scene scene2 = new Scene(pane, 250, 150);

这是搞乱程序的代码。由于某种原因,同时加载两个场景会弄乱显示。

关于JavaFx 阶段未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48047505/

相关文章:

java - 如何在JavaFX中制作自定义LineChart控件?

java - play - 将全局变量添加到自定义标签

java - 数数没有。在java中使用正则表达式的单词

java - 在 ObservableList 上调用 clear() 会导致 IndexOutOfBoundsException

java - 如何获取 JavaFX 的版本号?

java - 创建 bean 时出错 "entityManagerFactory"

java - 单击 JavaFX 按钮上的“删除卡”

java - 警告 "Call in violation of protocol"

java - 当我将参数与 PowerMockito 模拟静态方法一起使用时,为什么会出现参数类型不匹配的情况?

java - 如何获得 Child 类?