如何为 GUI 制作启动画面? [英] How to make a splash screen for GUI?

查看:30
本文介绍了如何为 GUI 制作启动画面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是 Java 图形用户界面的新手,我试图让启动画面或图像显示 3 秒.然后它会进入我的主程序.有没有人知道如何做到这一点,或者可以将我链接到任何教程?

Hi there I'm new to GUIs in Java and was trying to make a splash screen or an image appear for 3 seconds. Then after that it it will go onto my main program. Does anyone have an ideas how to do this or can link me to any tutorials?

到目前为止,我已经这样做了,但不知道从哪里开始.

So far I have done this but not sure where to go from here.

public static void main(String[] args)
{
    splashInit();           // initialize splash overlay drawing parameters
    appInit();              // simulate what an application would do 
}

推荐答案

最简单的一个,就是创建 JFrame 并在其上添加你的 screen 然后使用 Thread.Sleep(长毫秒)

Simplest one , is to create JFrame and add your screen on it then use Thread.Sleep(long millies)

试试这个代码:

JWindow window = new JWindow();
window.getContentPane().add(
    new JLabel("", new ImageIcon(new URL("http://docs.oracle.com/javase/tutorial/uiswing/examples/misc/SplashDemoProject/src/misc/images/splash.gif")), SwingConstants.CENTER));
window.setBounds(500, 150, 300, 200);
window.setVisible(true);
try {
    Thread.sleep(5000);
} catch (InterruptedException e) {
    e.printStackTrace();
}
window.setVisible(false);
JFrame frame = new JFrame();
frame.add(new JLabel("Welcome"));
frame.setVisible(true);
frame.setSize(300,100);
window.dispose();

或者您可以创建启动画面 使用 SplashScreen

Or you can Create a Splash Screen by using SplashScreen class

这篇关于如何为 GUI 制作启动画面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆