大家好,我是
Java的新手,并试图使闪屏或图像显示3秒钟.然后它会进入我的主程序.有没有人有想法如何做到这一点或可以链接到任何教程?
到目前为止,我已经做到了这一点,但不知道从哪里开始.
- public static void main(String[] args)
- {
- splashInit(); // initialize splash overlay drawing parameters
- appInit(); // simulate what an application would do
- }
解决方法
最简单的方法是创建JFrame并在其上添加屏幕然后使用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类来Create a Splash Screen