我有3个类,main.class,login.class,然后是splash-screen.class
我的启动画面中没有主屏幕,它只在main.class运行时运行,问题是我希望我的启动画面只显示3秒钟,然后它必须消失并显示登录.class (只有登录控件)
我该怎么做?
当我运行main时,splashscreen.class和login.class apear
答案 0 :(得分:1)
使用Swing Timer:
setRepeats(false)
。它的ActionListener应该隐藏初始框架,并显示Login框架答案 1 :(得分:-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()
方法的第一行调用此方法。