gpt4 book ai didi

java - 仅当 JFrame 在屏幕上可见时才执行代码提前执行

转载 作者:行者123 更新时间:2023-12-02 02:55:07 25 4
gpt4 key购买 nike

我有一个名为 splash_windowJFrame,我将其用作应用程序的启动画面,并且它首先显示。它有一个进度条,最初位于0%,我希望它更改为5%并尽快执行一些其他命令它对用户可见。
当我运行应用程序时,进度条的进度已经5%之前我的启动画面变得可见,我可以在控制台中看到我的其他命令正在执行。
我的问题是:如何才能使用户在屏幕上看到闪屏时立即执行命令?

我的代码:

//making the splash_window visible after adding all components to it
splash_window.setVisible(true);

//Used to detect when the splash_window is visible to the user
if (splash_window.isShowing()){

//Used to know if the splash_window is visible
System.out.print("Splash screen is complete and now visible." + System.lineSeparator());

//Method used to increase my progress by 5%
initProgress.setValue(getProgress(5));

//Other commands...
}

最佳答案

您可以向框架添加窗口监听器,并在窗口打开时更新进度。这是一个例子:

splash_window.addWindowListener(new WindowListener() {

@Override
public void windowOpened(WindowEvent e) {
initProgress.setValue(getProgress(5));
initProgress.revalidate();
}

...

});

关于java - 仅当 JFrame 在屏幕上可见时才执行代码提前执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43227923/

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