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

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

问题描述

您好我是新来的图形用户界面在Java中,并试图使一个启动画面或图像出现3秒钟。然后,这之后它会去到我的主程序。没有人有一个想法如何做到这一点还是可以链接到我的任何教程?

到目前为止,我已经做到了这一点,但不知道从哪里何去何从。

 公共静态无效的主要(字串[] args)
{
    splashInit(); //初始化飞溅覆盖绘图参数
    appInit(); //模拟应用程序会做什么
}


解决方案

最简单的一种,是创建的JFrame 并添加屏幕它然后使用 Thread.sleep代码(长米莉)

试试这个code:

 的JWindow窗口=新的JWindow();
window.getContentPane()。添加(
    新的JLabel(,新的ImageIcon(新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(真);
尝试{
    视频下载(5000);
}赶上(InterruptedException的E){
    e.printStackTrace();
}
window.setVisible(假);
JFrame的帧=新的JFrame();
frame.add(新的JLabel(欢迎));
frame.setVisible(真);
frame.setSize(300100);
window.dispose();

您可以创建一个闪屏通过使用 闪屏

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 
}

解决方案

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

Try this code:

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();

Or you can Create a Splash Screen by using SplashScreen class

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

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