Import javax.swing. *; import java.awt. *; / * jwindow is a container that can be displayed anywhere in the user desktop. Therefore, it is possible to use it constitute the SPLASH screen when the program is just run. * / Public class ESplash extends JWindow implements Runnable {private Thread thread = null; private Image logo = null; private Color bg_color = new Color (255, 255, 255); private Toolkit toolkit = getToolkit (); private int image_width; private int Image_height;
public ESplash () {logo = new ECreateIcon () getSplashImage ();. loadImage (logo, 0); image_width = logo.getWidth (this); image_height = logo.getHeight (this); setBackground (bg_color); setCursor (new Cursor (3)); setsize (image_width 10); // Setting JWindow's display position int xpos = (Toolkit.getScreensize (). Width - getSize (). Width/2; int ypos = (Toolkit. GetScreensize (). Height - getSize (). height/2; setbounds (xpos, ypos, getsize (). width, getsize (). height); setvisible (true);} / * Make an image with MediaTracker The correct load. After the image is loaded, the drawing will be drawn. * / Private void loading {if (image! = Null) {Mediatracker Tracker = New Mediatracker (this); tracker.addimage (image, id); try {tracker.waitforid (ID);} catch InterruptedException_ex) {}}}
/ * Draw an image on the JWindow part. * / Public void Paint (Graphics G) {g.drawImage (logo, 5, 5, image_width, image_height, this); // Setting the color G.SetColor of the font (New Color (102, 102, 150)); g. DrawString ("Initialization System ...", 7, getSize (). HEIGHT - 72); // Sets the background color of the rectangular box. G.SetColor (New Color (255, 255, 255)); // Draw a rectangular box G.FillRect (5, getSize (). Height - 70, 317, 7); g.drawRect (5, getSize (). HEIGHT - 70, 317, 7); // Reset Color G.SetColor (New Color (102, 102, 150)) in the rectangular box; for (int N = 0; n <317; n = 5) Try {// thread sleep 50 milliseconds thread.sleep (50L); // Filled rectangular box G.fillRect (5, getSize (). HEIGHT - 70, N, 5);} catch (exception_ex) {} } public void run () {// Set the mouse as a wait state setcursor (new cursor (3)); repaint ();}
Public void stop () {// End Thread thread = null; logo = null;}
/ / Update the graphics area to prevent a flicker during the drawing.
Public void update (graphics g) {Paint (g);}}
/
Import java.awt. *; import java.awt.image. *; import java.awt.event. *; import javax.swing. *;
public class ECreateIcon {private static Image splashimage; public ECreateIcon () {splashimage = getImageFromResource ( "resources / images / Esplash.gif");} // get the image private Image getImageFromResource (String image_path) {return Toolkit.getDefaultToolkit () getImage. (image_path);}
public ImageIcon createImageIcon (String filename) {String path = "/ resources / images /" filename; return new ImageIcon (. getClass () getResource (path));} public Image getSplashImage () {return splashimage;}}