如何为GUI制作启动画面?

Ali*_*ssa 9 java user-interface swing awt splash-screen

大家好,我是Java的新手,并试图使闪屏或图像显示3秒钟.然后它会进入我的主程序.有没有人有想法如何做到这一点或可以链接到任何教程?

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

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

Aly*_*mal 11

最简单的一种,就是创建JFrame并添加你的screen然后使用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();
Run Code Online (Sandbox Code Playgroud)

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

  • 正确的想法,错误的方向,从不在EDT中调用Thread.sleep或从EDT的外侧创建/修改Swing UI组件 (9认同)

And*_*son 10

另请参阅如何为基于AWT的启动功能创建启动画面.

飞溅图像