gpt4 book ai didi

java - 使用 Platform.exit() 终止 JavaFX 应用程序

转载 作者:行者123 更新时间:2023-12-01 12:32:00 26 4
gpt4 key购买 nike

我正在使用 JavaFX 2.2,并且我有一个扩展 Application 的类。这是我的代码:

Class A extends Application { 
public void Stage(final Stage primaryStage) { ... }
public void Start(){
launch();
}
btnLogin.setOnAction(new EventHandler<ActionEvent>() {
Platform.exit();
}
}

Class B{ }

Class C extends Application{
public void Stage(final Stage primaryStage) { ... }
public void Start(){
launch();
}
}

实际上,A类是登录界面;当我成功登录时它将关闭。然后屏幕由 platform.exit() 函数关闭。之后我在类 B 中执行 View 按钮,类 C 被调用,但存在一些问题。

java.lang.IllegalStateException: Application launch must not be called more than once

我只是使用 Platform.exit() 函数终止屏幕,但我不明白为什么它无法关闭。

最佳答案

Platform.exit() 实际上终止了整个 jfx。为了保证安全,只需调用一次 launch() 并显示/隐藏新窗口。

类似于:

Platform.setImplicitExit(false);//make fx running in backgound.
Platform.runLater/AndWait {//make sure u create window in jfx thread
//window creation/show code here.
}

关于java - 使用 Platform.exit() 终止 JavaFX 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25862222/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com