Make a welcome screen with swing
(Panasonic May 30, 2001 18:49)
Almost all stylish apps have a welcome screen. The Welcome screen is one of the ways to promote the product, and during the long application startup process, the Welcome screen is also used to indicate that the application is in the process of being prepared.
Here is one of the simplest welcome screen implementations:
Class SplashWindow1 extends JWindow
{
Public SplashWindow1 (String filename, Frame f)
{
Super (f);
JLabel L = new JLabel (new ImageIcon (filename));
Getcontentpane (). Add (L, borderlayout.center);
Pack ();
Dimension screensize =
Toolkit.getdefaulttoolkit (). Getscreensize ();
Dimension labelsize = L.getpreferredsize ();
setlocation (SCREENSIZE.WIDTH/2-LABELSIZE.WIDTH/2),
SCREENSIZE.HEIGHT/2-(LABELSIZE.HEIGHT/2));
SetVisible (TRUE);
ScreenSize = null;
Labelsize = null;
}
}
The SplashWindow1 class derives from the JWindow of swing. JWindow is a container that does not have various window elements, such as title bars, window management buttons, or even highlighted borders, that other windows have. Therefore, JWindow is very suitable for making the Welcome screen. The above code assumes that the graphics file is in the current directory. The graph is loaded into memory by ImageIcon, and then it is placed in the center of the JWindow. Next, the window is Pack (), which allows swing to resize the window to the appropriate size, and the last window is moved to the center of the screen.
If we run the above program, we can find that although the Welcome screen does appear in the center of the screen, but unfortunately, it does not close! To turn off the Welcome screen, we need to add more code:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.