When the application starts, if the initialization time is longer, usually need to arrange a welcome to use the program's start-up interface, after the initialization is complete, the interface automatically disappears, this is what is usually said Splash window (flash windows).
/************************************************ * program file name: Jsplashwindow.java * Function: Program start interface ************************* /import javax.swing.*;import java.awt.*;import java.net.*;p ublic class Jsplashwindow extends JWindow implements Runnable{thread Splashthread = Null;public Jsplashwindow () {JPanel splash = new JPanel (New BorderLayout ()); URL Url=getclass (). GetResource ("elephant.jpg");//Add an image under the same path as the Jsplashwindow.java file, with the image name Elephant.jpgif (url!=null) {Splash.add (New JLabel (new ImageIcon (URL)), borderlayout.center);} Setcontentpane (Splash);D imension screen = Gettoolkit (). Getscreensize ();//Get the Display resolution pack (); setSize (500,400); SetLocation ((Screen.width-getsize (). width)/2, (Screen.height-getsize (). Height)/2);//To center the window}public Void Start () { This.tofront ();//The current window shows Splashthread=new Thread (this) on the front; Splashthread.start ();} public void Run () {try{show (); Thread.Sleep (3000);} catch (Exception ex) {ex.printstacktrace ();} This.dispose ();//close window}static void Showframe (String title) {JFrame frame=new JFrame (tiTLE); Frame.setsize (+); Frame.setdefaultcloseoperation (jframe.exit_on_close);D imension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();D imension framesize=frame.getsize (); if (framesize.height> Screensize.height) {framesize.height=screensize.height;} if (framesize.width>screensize.width) {framesize.width=screensize.width;} Frame.setlocation ((screensize.width-framesize.width)/2, (Screensize.height-framesize.height)/2); Label Lb=new label ("Enter Application System"), Frame.getcontentpane (). Add (lb, borderlayout.center); Lb.setfont ("Default", 1,36)); Frame.setvisible (true);} public static void Main (string[] args) {showframe ("Do splash Window"); Jsplashwindow splash=new Jsplashwindow (); Splash.start ();}}
Program Start screen