![](/img/trans.png)
[英]How to show a splash-screen, load datas in the background, and hide the splash-screen after that?
[英]How to fix this code for splash-screen?
我正在尝试为游戏制作启动画面,这两个都是JFrames。 我希望启动屏幕打开3秒钟,然后将其丢弃。 游戏主体的JFrame需要创建并在随后立即显示。 我正在使用Thread.sleep()等待3秒,但加载页面延迟了3秒而不是游戏。 代码如下:
new load();
try
{
Thread.sleep(3000);
dispose();
new gameInfo();
}
catch (InterruptedException ex)
{
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
您需要在新线程上运行它,因为您现在所做的是冻结了主线程,它影响了GUI并使其也冻结了。 因此,您需要在后台等待3000毫秒,唯一简单的方法是创建一个新线程。 这是伪代码
new load();
new Thread(){
public void run(){
try {
Thread.sleep(3000);
//i think you should call this 2 lines below in main thread
dispose();
new gameInfo();
} catch (InterruptedException ex) {
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
此代码无法正常工作,这只是伪代码。 我需要查看整个课程以使其能够运行。
new load();
new Thread(){
public void run(){
try {
Thread.sleep(3000);
//i think you should call this 2 lines below in main thread
dispose();
new gameInfo();
} catch (InterruptedException ex) {
Logger.getLogger(home.class.getName()).log(Level.SEVERE, null, ex);
}
}
}.start();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.