2

我有 3 个类,main.class,login.class,然后是 splash-screen.class

我的启动画面中没有主屏幕,它只在 main.class 运行时运行,问题是我希望我的启动屏幕只出现 3 秒,然后它必须消失并显示登录 .class(它只是有控制登录)

我怎么做?

在我运行 main 的那一刻,spearscreen.class 和 login.class 都出现了

4

2 回答 2

1

使用摆动计时器

  • 显示启动画面
  • 创建一个延迟 3 秒的 Timer,然后调用setRepeats(false)此计时器。它的 ActionListener 应该隐藏启动框架,并显示登录框架
  • 启动计时器
于 2012-11-04T13:15:51.273 回答
-1

下面显示的代码可能对您有用:

 public static void showSplash(int duration) {
                SplashScreen splash1 = SplashScreen.getSplashScreen();
                if(splash1==null){
                File file1=new File("splash.jpg");
                String imgfile1=file1.getAbsolutePath();

                JWindow splash = new JWindow();
                JPanel content = (JPanel)splash.getContentPane();

                int width = 655;
                int height = 442;
                Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
                int x = (screen.width-width)/2;
                int y = (screen.height-height)/2;
                splash.setBounds(x,y,width,height);

                JLabel label = new JLabel(new ImageIcon(imgfile1));
                content.add(label, BorderLayout.CENTER);
                splash.setVisible(true);
            // Wait a little while, maybe while loading resources
                try
                {
                    Thread.sleep(duration);
                } catch (Exception e) {}
                splash.setVisible(false);
                }
            }

您可以在方法的第一行调用此main()方法。

于 2012-11-04T13:21:50.460 回答